Question

I am trying to compile a Silverlight project programatically. Initially I just wrapped MsBuild.exe, but had an error saying:

C:\Program Files (x86)\MSBuild\Microsoft\Silverlight\v5.0\Microsoft.Silverlight.Common.targets(104,9): The Silverlight 4 SDK is not installed.

I am using SilverLight 5 and have the SDK for both Silverlight 4 and Silverlight 5 installed. The solution compiles fine in Visual Studio. I followed the advice in this question:

MSBuild command-line error - Silverlight 4 SDK is not installed

I switched from running:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe

to:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe

This solved the problem, but due to a change in requirements I now need to use Microsoft.Build without wrapping the MsBuild exe. I have the following code:

var globalProperty = new Dictionary<string, string> { { "Configuration", "Debug"}, { "Platform", "Any CPU" } };
var buildParameters = new BuildParameters(new ProjectCollection()) { Loggers = new List<ILogger> { this.logger } };
var buildRequest = new BuildRequestData(@"C:\example\solution.sln", globalProperty, "4.0", new[] {"Build" }, null);
BuildResult buildResult = BuildManager.DefaultBuildManager.Build(buildParameters, buildRequest);

But again, I am now seeing:

ValidateSilverlightFrameworkPaths: ERROR C:\Program Files (x86)\MSBuild\Microsoft\Silverlight\v5.0\Microsoft.Silverlight.Common.targets(104,9): The Silverlight 4 SDK is not installed..

Is there a way to compile using x86 MsBuild from C# code without wrapping MsBuild.exe?

Was it helpful?

Solution

You have to set the target platform to "x86" in the project options of your "Build" project.

OTHER TIPS

I think you have to create a specific Process that will launch that specific MSBuild for you.

var p = new Process();
p.StartInfo = new ProcessStartInfo(@"C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe")      
p.StartInfo.Arguments = string.Format(@"{0}\{1}.csproj", _args.ProjectPath, _args.ProjectName)

p.Start();

Or whatever path for your solution.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top