hostmustsetmsbuildbinpathwheninstantiatingengine

Cancel Edit [WikiEntry.PreviewButtonText] Save

When I try to instantiate a new Project object, I get an exception about "Engine.BinPath" being null. What am I doing wrong?


Starting with the Beta 1 drop, all hosts of ""MSBuild"" must provide a value for ""MSBuildBinPath"" in order to use the object model. The way to do this is either to pass in the value in the Engine constructor as follows:

		 Engine myEngine = new Engine(@"c:\windows\microsoft.net\framework\v2.0.12345");
	

or set it post-construction:

		 Engine myEngine = new Engine();
		 [myEngine.BinPath] = @"c:\windows\microsoft.net\framework\v2.0.12345";
	

Followup: Why this mechanism? Why can't ""MSBuild"" figure out the value for ""MSBuildBinPath"" on its own?
Answer: Good question. ""MSBuild"" used to call ""Assembly.CodeBase"" to figure out where the binaries were running from. But starting with the Beta 1 release (not in ""PD5""), ""MSBuild"" assemblies are installed into the GAC. Therefore, ""Assembly.CodeBase"" would return us the GAC'd path, and this is not useful for the ""MSBuildBinPath"" property, because ""MSBuildBinPath"" is used to located our .TARGETS files, which are of course not in the GAC.
Microsoft Communities