Silverlight MSBuild Task - execute command line af

2019-02-28 07:12发布

问题:

I have a silverlight project arranged as follows:

  • Examples
    • Silverlight
      • Bin
        • Debug
    • ExampleCode
      • {Multiple Sub directories}
  • Silverlight.Web
    • Bin
      • Debug
        • ClientBin
          • Silverlight.Web.xap

The code under {Multiple Sub Directories} is included in the silverlight DLL and compiled, however I also want to include these files as "Content" in the xap file. Think about demo applications for .NET controls that show you a demo but also the C#/xaml code to achieve it. This is what I'm trying to do.

  • I cannot select include as content as they are already included as compile
  • I cannot include the files twice and compile one and content the other as VS2010 won't let you.

I would like to include all the files/folders under the Examples/Silverlight/ExampleCode folder in the output xap file. To achieve this I attempted a post-build event on the Silverlight.Web project. The syntax is below:

"$(SolutionDir)..\Lib\7Zip\7z.exe" a  -tzip 
    "$(ProjectDir)ClientBin\Silverlight.Web.xap" 
    "$(SolutionDir)Examples\Silverlight\Bin\Debug\ExampleCode"

Now if I execute this in a console window it works perfectly. The xap file is updated. However if I execute it from the post-build event in Silverlight.Web nothing happens (no failure, just nothing).

I assume that the post-build event is fired before the xap file is created.

Does anyone know how I can run a MSbuild task or command line post-build event with arguments after the xap file is copied to ClientBin?

回答1:

You can work around this by adding your files to XapFilesInputCollection in an AfterCompile target of your Silverlight project. Note however that including a bin folder directly in the project may result with an access denied error when compiling in Visual Studio.

<Target Name="AfterCompile">
  <ItemGroup>
    <XapFilesInputCollection Include="$(SolutionDir)Examples\Silverlight\Bin\$(Configuration)\ExampleCode"/>
  </ItemGroup>
</Target>