1

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?

Community
  • 1
  • 1
infojolt
  • 5,244
  • 3
  • 40
  • 82
  • Have you tried to set the target platform to "x86" in the project options (I'm not sure if that helps but might be worth a try)? – andyp Mar 25 '14 at 20:19

2 Answers2

5

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

rschmidt
  • 166
  • 3
  • Giving the bounty to this answer. I had to create a new project targeting x86. Then using the exact code I included above works when building the target project in 'Any CPU'. – infojolt Apr 01 '14 at 08:29
1

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.

a.boussema
  • 1,096
  • 11
  • 19
  • This is the way I was doing it previously. Unfortunately this no longer meets my requirements as I need to pass in a bespoke logger to extract warnings/errors in a particular way. – infojolt Mar 26 '14 at 23:03
  • and what about using the /fileLogger option and get the logging output from file. Have you got a look at this http://msdn.microsoft.com/en-us/library/ms164311.aspx – a.boussema Mar 27 '14 at 07:44
  • I need to get real-time logging output. I don't want to write to file and then parse as I won't be able to output in the required format until the build has finished. – infojolt Mar 31 '14 at 09:23