Home » Visual StudioRSS

Building solution programatically in VS 2010

In VS 2008, I used:

Microsoft.Build.BuildEngine engine = new Microsoft.Build.BuildEngine;

engine.RegisterLogger(logger);

engine.BuildProjectFile(projectPath)

where:

projectPath was the path to the TFSBuild.proj file.  The TFSBuild.proj file containted the name of the solution to build and I had as many files as I had solutions that needed to be built.

 

How do I do this for VS 2010 solutions?

I found how to build the VS 2008 solutions in VS 2010:

Microsoft.Build.Evaluation.Project p = new Microsoft.Build.Evaluation(path);

where path is again the path to the TFSBuild.proj file.

However, I don't see a TFSBuild.proj file in VS 2010 (everything is a workflow), so how do I go about doing this?  I have an app that will need to build VS 2008 solutions, along with VS 2010 solutions.  I'm thinking I'll have to rewrite the app in VS 2010 since the Microsoft.BuildEngine.Engine class is obselete and I need to use Microsoft.Build.Evaluation.  However, I don't understand how to use Microsoft.Build.Evaluation to build VS 2010 solutions. 

 

 

 

 

 

 

Thanks.

rojectPath);
 

9 Answers Found

 

Answer 1

Hi, Builder9999

I have answered this question several days ago. To build a solution, all we need to do is to set the BuildRequestData Properly.

Please see this link. http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/ec95c513-f972-45ad-b108-5fcfd27f39bc

Thanks

Chao

 

 

Answer 2

Thank you for the prompt reply.  This did indeed work but I see the dlls in the various project folders under bin\Debug. 

When I used the following for the VS 2008 solutions:

Microsoft.Build.Evaluation.Project p = new Microsoft.Build.Evaluation

bool result = p.Build()

as shown in my original post, all dlls *for the VS 2008 solution* were output to following shared folder by MSBuild:

C:\Binaries\Debug

This was what I saw in VS 2008 when I used:

Microsoft.Build.BuildEngine engine = new Microsoft.Build.BuildEngine;

bool status engine.BuildProjectPath(projectPath)

 

How do I get this behaviour for a VS 2010 solution?

Thanks.

 

 

Answer 3

Hi, Dude

If you want to change the output path, all we need to do is to set the property.

See the code based on the original code.

            string projectFileName = @"\visual studio 2010\Projects\ConsoleApplication1\ConsoleApplication1.sln";

            ProjectCollection pc = newProjectCollection();

            Dictionary<string, string> GlobalProperty = newDictionary<string, string>();

            GlobalProperty.Add("Configuration", "Debug");

            GlobalProperty.Add("Platform", "x86");

            //Here, we set the property

            GlobalProperty.Add("OutputPath",@"D:\Output");

            BuildRequestData BuidlRequest = newBuildRequestData(projectFileName, GlobalProperty, null, new string[] { "Build" }, null);

            BuildResult buildResult = BuildManager.DefaultBuildManager.Build(newBuildParameters(pc), BuidlRequest);

Thanks

Chao

 

Answer 4

Thanks again, that did the trick.  I did try that but it didn't work bc I didn't know what the property was called.  I tried:

GlobalProperty.Add("BinariesSubdirectory", "Binaries")

"BinariesSubdirectory" was the name of the property in the MSBuild of VS 2008.  Where can I get a list of the names of the properties so that I may assign values to them?  (I.e., where did you get the names "Configuration", "Platform" and "OutputPath"?)

Also, how do I incorporate logging into the VS2010 build?  For the VS 2008 solution, I am able to pass a logger to the Build() method as follows:

Microsoft.Build.Evaluation.Project p = new Microsoft.Build.Evaluation.Project(myProject);

ILogger logger = new MyLogger();

logger.Verbosity = LoggerVerbosity.Detailed;

p.Build(logger);

I tried the following for the VS 2010 solution, but it didn't work.  Do I need to change the logger to work with VS2010?  Or, is this not the correct way to add logging?

string projectFileName = @"C:\Solutions\MySolution.sln";

ILogger logger = new MyLogger();

logger.Verbosity = LoggerVerbosity.Detailed;

Microsoft.Build.Evaluation.ProjectCollection pc = new ProjectCollection();

pc.RegisterLogger(logger);

GlobalProperty.Add("Configuration", "Debug");

GlobalProperty.Add("Platform", "x86");

BuildRequestData buildRequest = new BuildRequestData(projectFileName, GlobalProperty, null, new string[] {" Build"}, null);

BuildResult result = BuildManager.DefaultBuildManager.Build(new BuildParameters(pc), buildRequest);

 

 

 

 

 

Answer 5

Hello,

I also do not know how to get the global properties, I just guess the global properties. I think building  a solution  is different from building a MSBuild Script project.

For the custom logger failing to work, I also don’t know the reason because there are little document about this. I have consult the discussion group, maybe a hero could resolve this issue for us.

Thanks

Chao

 

PS: I close this thread and I will be back as soon as I get the answer.

 

Answer 6

OK, thank you.
 

Answer 7

Hello, Builder

I am back.

After consulting Dan, I got an answer. We need set the BuildParameters.Loggers Property of the BuildParameters class.

Thanks

Chao

 

Answer 8

Thanks again, that worked.  Any word on what the properties should be called?
 

Answer 9

Hello, Builder

I just guess them, because for plateform and configuration are global to all the projects in a solution. we should notice that building  a solution  should be different from building project.

Thanks

Chao

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter