I am trying to execute MSBuild programmatically and can't execute the following command:
string command = string.Format(@"C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe ""{0}\{1}.csproj""", _args.ProjectPath, _args.ProjectName);
The string gets rendered as:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe "C:\...\TestResults\Foo 2011-08-31 16_29_40\Out\Foo\solutionName\projectName\projectName.csproj"
I then use new ProcessStartInfo(command). The problem seems to be the space between Foo and 2011. I get the following output:
MSBUILD : error MSB1008: Only one project can be specified. Switch: 16_29_40\Out\Foo\solutionName\projectName\projectName.csproj
How do I pass in the project file to MSBuild?
To run MSBuild at a command prompt, pass a project file to MSBuild.exe, together with the appropriate command-line options. Command-line options let you set properties, execute specific targets, and set other options that control the build process.
NET Framework 3.5 or later. MSBuild provides an easy way to build a release from the command line on a machine on which Visual Studio is not installed. The only components you must have installed on the machine are the . NET Framework and the InstallShield Standalone Build.
To build a specific target of a specific project in a solution. At the command line, type MSBuild.exe <SolutionName>. sln , where <SolutionName> corresponds to the file name of the solution that contains the target that you want to execute.
To enable msbuild in Command Prompt, you simply have to add the directory of the msbuild.exe install on your machine to the PATH environment variable. You can access the environment variables by: Right clicking on Computer. Click Properties.
I would recommend stronlgy to go the official route via classes/interfaces in Microsoft.Build
namespace. Microsoft uses this all over the place, so this should count for something...
Esp. the class Microsoft.Build.Execution.BuildManager
and the Singleton Microsoft.Build.Execution.BuildManager.DefaultBuildManager
is what you are after to run a build task... source code examples:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With