what's an effective way to build a csproj file in code?
I'd like to avoid a command line for this. I've been using the MSBuild API ( Microsoft.Build.Framework
and
Microsoft.Build.BuildEngine
) with code that looks like this:
this.buildEngine = new Engine();
BuildPropertyGroup props = new BuildPropertyGroup();
props.SetProperty("Configuration", "Debug");
this.buildEngine.RegisterLogger(this.logger);
Project proj = new Project(this.buildEngine);开发者_如何学C
proj.LoadXml(this.projectFileAndPath, ProjectLoadSettings.None);
this.buildEngine.BuildProject(proj, "Build");
However I've run into enough problems that I can't find answers for that I'm really wondering if I'm doing this right. First, I can't find the output (there's no bin directory in any of the places where I figured the dll's would end up). Second, I tried building a project that I had made in VS2008 and the line proj.LoadXml(
fails for invalid xml encoding. But of course the xml file is valid, since VS2008 can build it (I checked).
At this point I'm beginning to wonder if I've picked up some code that's way out of date or a methodology that's been superseded by something else. Opinions?
The LoadXml() method expects a string that contains the xml, not a path to a file. Use the Load() method instead.
No, there's nothing out-of-date about the Microsoft.Build namespace. Assuming you are using the 3.5 version.
精彩评论