0

I have solution with some C# project in visual studio. In another project user can show all projects in first solution. User select some project to build. also select between Release/Debug and x64/x86/any.

I can build one project with this code

Microsoft.build.Evaluation.project p = new Microsoft.build.Evaluation.project(project_path);
p.Build();

But I don't know how to build project with selected Release/Debug and x64/x86/any.

How can I change build destination directory?

General Grievance
  • 4,555
  • 31
  • 31
  • 45
sharafi
  • 531
  • 1
  • 7
  • 19

1 Answers1

1
Microsoft.Build.Evaluation.Project p = new Microsoft.Build.Evaluation.Project("path");
p.SetGlobalProperty("Configuration", "Release");
p.Build();

Should let you change the configuration used to build your project. Substitute "Configuration" for "Platform" if you wish to alter that.

Adam Lopes
  • 74
  • 2
  • how to select x64/x86 ? – sharafi Oct 31 '19 at 10:14
  • Have not tested it, however I believe it is p.SetGlobalProperty("Platform", "x86"); – Adam Lopes Oct 31 '19 at 10:31
  • I'm not 100% sure, but you may not be able to call SetGlobalProperty more than once on the Project object. Have you tried modifying the GlobalProperties dictionary of the project object, or at least inspecting it in the debugger. (e.g. p.GlobalProperties.Add("Configuration", "Release"); p.GlobalProperties.Add("Platform", "Any CPU");) Also, you need to make sure that the build configuration and platform are actually defined for the project in question – Adam Lopes Oct 31 '19 at 11:30
  • How can I change build destination directory? – sharafi Oct 31 '19 at 14:04
  • This is usually set in the project file configuration. Is there any reason you need to do it programmatically? Also, if my answer solved your problem, could you please mark it as "answered". – Adam Lopes Jan 01 '20 at 19:49