views:

510

answers:

1

I have a process where I need to automate the process of generating the satellite assemblies. Specifically this is for WPF and combining Resx and BAML resources.

I've got a build script that works, but it requires manual adding of the .resources files I want to combine with the BAML resources. IOW, I have to add to the build script each time I add a .Resx resource. Not cool!

Currently I'm running the assembly linker manually and the script looks like this:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
  <!-- Adds the build action 'LocBamlCsv' -->
  <ItemGroup>
    <AvailableItemName Include="LocBamlCsv" />
  </ItemGroup>


  <Target Name="CreateSatelliteAssemblies"
          DependsOnTargets="$(CreateSatelliteAssembliesDependsOn)">

    <!-- Locbaml needs the runtime assemblies in the intermediate dir -->
    <Copy SourceFiles="$(ProjectDir)..\Tools\LocBaml.exe"
          DestinationFolder="$(OutputPath)" />


    <!-- generate a .resources file for .csv merged output -->
    <Exec Command="LocBaml /generate ..\..\$(IntermediateOutputPath)$(TargetName).g.$(UICulture).resources /trans:%(LocBamlCsv.FullPath) /out:../../$(IntermediateOutputPath) /cul:%(LocBamlCsv.Culture)"
          WorkingDirectory="$(OutputPath)"
          Outputs="$(OutputPath)%(LocBamlCsv.Culture)\$(TargetName).$(UICulture).dll" />

    <!-- Generate the resource assembly by merging all .resources files -->
    <!-- NOTE: Explicitly add any resource files here -->
    <Exec Command="al /template:$(TargetName).exe /culture:%(LocBamlCsv.Culture) /out:%(LocBamlCsv.Culture)\$(TargetName).resources.dll /embed:$(TargetName).g.%(LocBamlCsv.Culture).resources /embed:$(TargetName).Properties.Resources.%(LocBamlCsv.Culture).resources"
          WorkingDirectory="$(InterMediateOutputPath)"
          />


  </Target>
</Project>

As mentioned it works. but the last command that calls al would be much easier to work with if there was some way to use wild cards (ie. $(TargetName).*s.%(LocBamlCsv.Culture).resources.

I've tried a number of things. Using the build process apparently fires at the wrong time and it ends up failing to find files.

+1  A: 

Hi, I'm not sure exactly what your problem is but you did say something that makes me wonder. "Using the build process apparently fires at the wrong time and it ends up failing to find files." From this I get the impression that you are trying to create an item which contains files that are generated during the build process. If this is the case then you should declare those as dynamic items, which are items declared inside of a target. Items declared outside of targets (static items) are evaluated before any target begins to execute. See my blog post MSBuild: Property and Item Evaluation.

Sayed Ibrahim Hashimi
Sayed thanks for your tip. This did end up pointing me in the right direction although this wasn't the exactly problem. The issue is that I build my resource assembly into the intermediate folder and apparently the normal build process would overwrite it. I change my code to write the final assembly directly into the target output satellite folder and that now works reliably. Not sure why *that* doesn't get overwritten, but it seems to work.Will check out your book. Glad to see there's one on MsBuild - last I looked there was nothing.
Rick Strahl