1

我有一个需要自动化生成附属程序集的过程的过程。具体来说,这是针对 WPF 和结合 Resx 和 BAML 资源的。

我有一个可以工作的构建脚本,但它需要手动添加我想与 BAML 资源结合的 .resources 文件。IOW,每次添加 .Resx 资源时,我都必须添加到构建脚本中。不酷!

目前我正在手动运行程序集链接器,脚本如下所示:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!-- 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>

如前所述,它有效。但如果有某种方法可以使用通配符(即 $(TargetName).*s.%(LocBamlCsv.Culture).resources.

我已经尝试了很多东西。使用构建过程显然在错误的时间触发,最终无法找到文件。

4

1 回答 1

1

我不确定你的问题到底是什么,但你确实说了一些让我想知道的话。“使用构建过程显然在错误的时间触发,最终无法找到文件。” 从这里我得到的印象是您正在尝试创建一个包含在构建过​​程中生成的文件的项目。如果是这种情况,那么您应该将它们声明为动态项目,它们是在目标内部声明的项目。在目标之外声明的项目(静态项目)在任何目标开始执行之前进行评估。请参阅我的博文 MSBuild:属性和项目评估。

赛义德·易卜拉欣·哈希米

我的书:Microsoft Build Engine 内部:使用 MSBuild 和 Team Foundation Build

于 2009-06-15T00:01:31.937 回答