Skip to main content

Microsoft Silverlight

Unanswered Question Compiling Silverlight apps with Microsoft.Build.BuildEngine or CodeDomProviderRSS Feed

(0)

joshcomley
joshcomley

Member

Member

54 points

46 Posts

Compiling Silverlight apps with Microsoft.Build.BuildEngine or CodeDomProvider

Has anyone had any luck compiling Silverlight apps dynamically?

I have a project that compiles fine with the following command line:

"C:\Windows\Microsoft.NET\Framework\v3.5\msbuild.exe" "Test.csproj" /Property:OutDir="/build/"

I can then zip up, rename to .xap and off I go, all is OK.

But not with the following code:

1    // Create a new Engine object.
2 Engine engine = new Engine();
3
4 // Register the logger
5 CustomBuildLogger logger = new CustomBuildLogger();
6 engine.RegisterLogger(logger);
7
8 bool success = engine.BuildProjectFile(@"C:\Test\Test.csproj");

The above code produces the following error in my CustomBuildLogger:

The "EntityDeploy" task could not be instantiated from the assembly "C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Data.Entity.Build.Tasks.dll". Please verify the task assembly has been built using the same version of the Microsoft.Build.Framework assembly as the one installed on your computer and that your host application is not missing a binding redirect for Microsoft.Build.Framework. Unable to cast object of type 'Microsoft.Data.Entity.Build.Tasks.EntityDeploy' to type 'Microsoft.Build.Framework.ITask'.

I have also tried the CodeDomProvider:

 

1    CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("CSharp");
2 System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters(
3 new string[] {
4 @"C:\Program Files (x86)\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies\mscorlib.dll",
5 @"C:\Program Files (x86)\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies\system.dll",
6 @"C:\Program Files (x86)\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies\System.Core.dll",
7 @"C:\Program Files (x86)\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies\System.Net.dll",
8 @"C:\Program Files (x86)\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies\System.Windows.dll",
9 @"C:\Program Files (x86)\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies\System.Windows.Browser.dll",
10 @"C:\Program Files (x86)\Microsoft SDKs\Silverlight\v2.0\Reference Assemblies\System.Xml.dll",
11 }
12 );
13 // Make sure we generate a DLL
14 parameters.GenerateExecutable = false;
15
16 parameters.OutputAssembly = Output;
17 //parameters.CompilerOptions = "/t:library /nostdlib+ /noconfig";
18 CompilerResults results = codeProvider.CompileAssemblyFromDom(parameters);

This produces a DLL, but not one I can zip up into a .xap file that will work. I have also tried the Project.LoadXml() method.

Please note my project has no XAML files in it, so I should be able to use the CodeDomProvider (as far as I am aware).

I am running Visual Studio 2008 SP1 on Vista x64.

I have ensured my app generating the code is set to x86 runtime, so that the Tools directory is set to the x86 MSBuild.

This seems a similar problem to this old and unresovled post:

http://silverlight.net/forums/p/19138/65682.aspx#65682

Any help would be much appreciated!

ken tucker
ken tucker

All-Star

All-Star

15738 points

2,390 Posts

Re: Compiling Silverlight apps with Microsoft.Build.BuildEngine or CodeDomProvider

http://timheuer.com/blog/archive/2008/10/10/where-is-chiron-in-silverlight-2-release.aspx

 

 

joshcomley
joshcomley

Member

Member

54 points

46 Posts

Re: Compiling Silverlight apps with Microsoft.Build.BuildEngine or CodeDomProvider

Hi Ken, Thanks for your brief but useful reply!

I had looked in to Chiron.exe, but the point of doing things from code was to try and use the MSBuild API to do everything programmatically and avoid running command line apps and creating physical CSProj files.

As I say, I can use MSBuild from command line and it's fine. Then I zip it up in C# and rename to .xap and I'm ready to go.

I ultimately want to use Project.LoadXml(...) to dynamically generate DLLs at runtime without having to create any physical CSProj build files. I want to do this to keep as much as possible in memory and not on the HDD as this will slow things down.

For the moment, I can survive but it's not as scaleable as I'd like. I need to make a LOT of DLLs all day.

Thanks,
Josh

joshcomley
joshcomley

Member

Member

54 points

46 Posts

Re: Compiling Silverlight apps with Microsoft.Build.BuildEngine or CodeDomProvider

Anyone?

olgajay
olgajay

Member

Member

2 points

1 Posts

Re: Compiling Silverlight apps with Microsoft.Build.BuildEngine or CodeDomProvider

Hi,

I'm interesting in compiling Silverlight projects without creating csproject too.

joshcomley
joshcomley

Member

Member

54 points

46 Posts

Re: Compiling Silverlight apps with Microsoft.Build.BuildEngine or CodeDomProvider

I'm guessing no one knows how to do this...

joshcomley
joshcomley

Member

Member

54 points

46 Posts

Re: Compiling Silverlight apps with Microsoft.Build.BuildEngine or CodeDomProvider

OK well obviously the problem is that using MSBuild namespace in C# to compile a Silverlight application is binding somehow to the full .NET 3.5 framework.

I need a binding redirect to the Silverlight version of the .NET framework.

The big question is: why does it work at command line with the exact same project file?

hunraken
hunraken

Member

Member

4 points

2 Posts

Re: Compiling Silverlight apps with Microsoft.Build.BuildEngine or CodeDomProvider

Hi Josh,

Were you able to resolve this problem ?, I am attempting the same, reading else were the suggestion was to redirect the proper 3.5 assemblies on compile time via the following configuration section in an App.config:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Build.Framework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="3.5.0.0"/>
        <assemblyIdentity name="Microsoft.Build.Engine" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="3.5.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

 

tried it but I am still getting the same problem:

 

C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Data.Entity.targets(40,5): error MSB4127: The "EntityDeploy" task could not be instantiated from the assembly "C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Data.Entity.Build.Tasks.dll". Please verify the task assembly has been built using the same version of the Microsoft.Build.Framework assembly as the one installed on your computer and that your host application is not missing a binding redirect for Microsoft.Build.Framework. Unable to cast object of type 'Microsoft.Data.Entity.Build.Tasks.EntityDeploy' to type 'Microsoft.Build.Framework.ITask'.
C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Data.Entity.targets(40,5): error MSB4060: The "EntityDeploy" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name.
    0 Warning(s)

ccoombs
ccoombs

Contributor

Contributor

5018 points

743 Posts

Re: Re: Compiling Silverlight apps with Microsoft.Build.BuildEngine or CodeDomProvider

 this section must be placed in the app.config of the executable that contains the call to engine.BuildProjectFile:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Build.Framework" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="3.5.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.CompactFramework.Build.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="9.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Build.Engine" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-99.9.9.9" newVersion="3.5.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

 

if you move YourProject.exe (the one that calls engine.BuildProjectFile) out of the debug directory, app.config has to go with it as a separate distributable.  however outside of the debug directory it must reside in the same directory as YourProject.exe and be renamed YourProject.exe.config, just like any app.config distribution.

hunraken
hunraken

Member

Member

4 points

2 Posts

Re: Re: Compiling Silverlight apps with Microsoft.Build.BuildEngine or CodeDomProvider

Thanks ccoombs,

 I did get it to run following your procedure, I was placing the app.config in the target silverlight project and not the one that performs the BuildEngine call. Once that was corrected it worked beatifully... until last couple of days that I migrated to Silverlight 3.0, error is now:

    Target EntityDeploy:
        Processing 0 EDMX files.
        Finished processing 0 EDMX files.
    Target MarkupCompilePass1:
        C:\Program Files\MSBuild\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.Common.targets(169,9): error MSB4061: The "CompileXaml" task could not be instantiated from the assembly "C:\Program Files\MSBuild\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.Build.Tasks.dll". Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
        C:\Program Files\MSBuild\Microsoft\Silverlight\v3.0\Microsoft.Silverlight.Common.targets(169,9): error MSB4060: The "CompileXaml" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name.
    Done building target "MarkupCompilePass1" in project "SlickClientLib.csproj.xml" -- FAILED.

   

I appreciate if you guys have any suggestions.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities