4

我正在使用SlowCheetah XML Transforms扩展来处理带有 app.config 的类似 web.config 的转换。那部分效果很好。

我添加了一个安装项目并将其配置为包含第一个项目的项目输出。我注意到当我运行安装程序时,它安装了未转换的 app.config。查看主要输出 Outputs(说快 10 倍),我注意到它在 中找到二进制文件Project\bin\Debug\Project.exe,但Project.exe.config来自Project\app.config而不是Project\bin\Debug\Project.exe.config.

我可以将 app.config 从主输出中排除,并将路径硬编码到特定配置的 app.config ( Project\bin\Debug\Project.exe.config),但是无论我使用哪种配置来构建它,我都会得到相同的 app.config。

是否有在安装项目中获取适当转换的 app.config 的解决方法?

4

2 回答 2

3

您好,我们计划在接下来的几天内发布一个支持 ClickOnce 的新版本。如果您之前需要构建插件而不是修复,请与我联系,我可以将其发送给您。

于 2012-01-26T23:40:15.330 回答
1

这可能不是您正在寻找的答案,但我之前曾为如何将正确的 app.config 文件放入安装项目而苦苦挣扎。我有一个使用转换的 TFSBuild.proj msbuild 文件。我认为 SlowCheetah 转换使用相同的 msbuild 任务,但我可能不正确。当使用转换文件时,SlowCheetah 无疑提供了更有用的用户体验。我的构建文件采用了稍微不同的方法。在自动构建结束时,我想为每个目标部署环境生成安装程序。我使用了许多 msbuild 扩展,包括TransformXml构建任务 - 以下并非全部需要,但 FWIW 这些是导入:

<!-- import extensions -->
<Import Project="$(MSBuildExtensionsPath)\ExtensionPack\MSBuild.ExtensionPack.tasks"/>
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
<UsingTask TaskName="TransformXml"
       AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>

我定义了以下环境:

<ItemGroup>
  <!-- target deployment environments -->
  <Configs Include="Prod" />
  <Configs Include="Staging" />
  <Configs Include="Test" />
</ItemGroup>

然后标准的AfterCompileSolution目标包含对为每个环境生成安装程序的目标的调用:

<Target Name="AfterCompileSolution">

  <!-- Create installers for target deployment environments -->
  <CallTarget Targets="MyProject" />

</Target>

<Target Name="MyProject" Outputs="%(Configs.Identity)">
  <ItemGroup>
    <MyProjectTempConfig Include="$(SolutionRoot)\MyProjectService\Temp.config" />
    <MyProjectConfigFrom Include="$(SolutionRoot)\MyProjectService\App.%(Configs.Identity).config" />
    <MyProjectConfigTo Include="$(SolutionRoot)\MyProjectService\App.config">
      <Attributes>ReadOnly</Attributes>
    </MyProjectConfigTo>
  </ItemGroup>

  <Message Text="MyProject - Target environment: %(Configs.Identity)" />

  <!-- transform app.config using appropriate -->
  <Copy SourceFiles="@(MyProjectConfigTo)"
        DestinationFiles="@(MyProjectTempConfig)"
        OverwriteReadOnlyFiles="true"
        ContinueOnError="true"
        Condition="!Exists(@(MyProjectTempConfig))"/>

  <File TaskAction="RemoveAttributes" Files="@(MyProjectConfigTo)"/>

  <TransformXml Source="@(MyProjectTempConfig)"
                Transform="@(MyProjectConfigFrom)"
                Destination="@(MyProjectConfigTo)" />

  <!-- run setup -->
  <Exec Command="&quot;$(ProgramFiles)\Microsoft Visual Studio 10.0\Common7\IDE\devenv&quot; &quot;$(SolutionRoot)\MyProject.sln&quot; /build Release /project MyProjectService.Setup"/>

  <!-- rename output for target deployment environment -->
  <Copy SourceFiles="$(SolutionRoot)\MyProjectService.Setup\Release\MyProjectService.msi"
        DestinationFiles="$(OutDir)\%(Configs.Identity)_MyProjectService.msi"
        OverwriteReadOnlyFiles="true"
        ContinueOnError="true"/>

</Target>
于 2012-01-26T22:51:47.003 回答