Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running MSBuild programmatically

Tags:

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?

like image 901
foo Avatar asked Aug 31 '11 23:08

foo


People also ask

How do I run MSBuild command?

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.

Can I use MSBuild without Visual Studio?

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.

How do I run MSBuild target?

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.

How do I open MSBuild exe?

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.


1 Answers

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:

  • http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/ec95c513-f972-45ad-b108-5fcfd27f39bc/
  • Logging Build messages with MSBuild 4.0
like image 157
Yahia Avatar answered Sep 27 '22 16:09

Yahia