【问题标题】:SlowCheetah transforms for non-web app.config非 web app.config 的 SlowCheetah 转换
【发布时间】:2013-03-20 12:07:57
【问题描述】:

我对 Sayed Hashimi 和公司在 SlowCheetah 上完成的快速和出色的工作感到困惑,特别是 SlowCheetah 是否能够在 Build 上转换文件而不仅仅是打包和发布。

我安装了 SlowCheetah,并且能够为我正在与开发团队合作部署的控制台应用程序的 app.config 自动生成构建配置实例。在构建时,会在 $(ProjectDir)\obj\x86\$(BuildConfig) 目录下创建一个新的“SlowCheetah”目录。例如,obj\x86\STAGE\SlowCheetah 目录包含一个 app.config 文件,当右键单击 STAGE 转换并选择“查看转换”时,转换完成。

但是,\bin\$(BuildConfig) 目录包含未转换的 app.config 文件以及每个 $(BuildConfig) 转换的所有模板 - 而不是替换 bin 中的 app.config 文件\x86\STAGE 目录,其中包含来自 SlowCheetah 的目录。

构建完成,没有错误。

这是预期的操作,还是仍然无法正常工作?

@sayed-ibrahim-hashimi 每个 $(Configuration) 都有一个转换。在 Visual Studio 中查看时转换正确显示,并在 \obj 目录树下的 \slowcheetah 目录中正确转换。转换示例如下:

<?xml version="1.0" encoding="utf-8" ?>
<!-- For more information on using transformations see the web.config examples at http://go.microsoft.com/fwlink/?LinkId=214134. -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform
<connectionStrings>
<add name="Portal" connectionString="Data Source=transformtestserver.domain.local;Initial Catalog=TestDB;User Id=TestUser;Password=testpw1;" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
<add name="DictionaryDatabase" connectionString="Data Source=transformtestserver.domain.local;Initial Catalog=TestDB;User Id=TestUser;Password=testpw2;" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
<add name="LoggingDatabase" connectionString="Data Source=transformtestserver.domain.local;Initial Catalog=TestDB;User Id=TestUser;Password=testpw3;" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>    
</connectionStrings>
</configuration>

问题可能与 Nuget/解决方案配置有关。我正在处理的项目是一个非常大的解决方案的一部分。我很难安装并运行 SlowCheetah - 有一次发现 Nuget 说已安装 SlowCheetah,但解决方案包目录不包含 SlowCheetah。

我在 TeamCity 中设置了一个解决方法,从 \obj 目录中提取转换后的 app.config 文件,但我真的很想解决这个问题,以便我可以将 SC 推广到完整的开发组。是否有详细的日志可供我们查看以指出详细信息?

【问题讨论】:

  • App.config 应该在构建时进行转换。你能在这里给出更具体的复制步骤吗?您可以尝试插入转换来查看源文件是否正在被修改?
  • 回复部分没有提供足够的空间来详细回答,对您的问题的详细回答附有示例转换,以@sayed-ibrahim-hashimi开头
  • @stackoverflow.com/users/105999/sayed-ibrahim-hashimi 我在 VS2010 中打开了诊断输出,看到 app.config 正在被转换并保存为 application.exe.config - 其中确实包含正确转换的 web.$(条件)。配置文件。我查看了 exe.config 文件的详细信息,发现这是 Windows 可执行文件的正确行为。我正在寻找一个 app.config 文件。看起来我在这上面浪费了你的时间——感谢你的反应灵敏并编写了很棒的应用程序和书籍。您的 MSBUILD 第 2 版。由于某种原因,每周使用最多。
  • @EHuggins 我遇到了一个非常相似的问题。尽管我在 App.config 文件中引用了其他配置文件;我希望转换这些配置文件的内容。像您一样,我看到了输出 Application.exe.config,但这只是其中包含指向所引用配置文件的原始链接,并且文件本身不会以任何方式进行转换。有任何想法吗?任何建议都非常感谢。

标签: visual-studio-2010 visual-studio msbuild slowcheetah


【解决方案1】:

我遇到了同样的问题。

VS 中的本地编译效果很好, 但是在构建代理(TeamCity)时,转换魔法没有发生!

我找到的与 xml 元素在 proj 文件中的位置有关的解决方案

  <PropertyGroup Label="SlowCheetah">
    <SlowCheetahToolsPath>$([System.IO.Path]::GetFullPath( $(MSBuildProjectDirectory)\..\packages\SlowCheetah.2.5.10.3\tools\))</SlowCheetahToolsPath>
    <SlowCheetah_EnableImportFromNuGet Condition=" '$(SC_EnableImportFromNuGet)'=='' ">true</SlowCheetah_EnableImportFromNuGet>
    <SlowCheetah_NuGetImportPath Condition=" '$(SlowCheetah_NuGetImportPath)'=='' ">$([System.IO.Path]::GetFullPath( $(MSBuildProjectDirectory)\Properties\SlowCheetah\SlowCheetah.Transforms.targets ))</SlowCheetah_NuGetImportPath>
    <SlowCheetahTargets Condition=" '$(SlowCheetah_EnableImportFromNuGet)'=='true' and Exists('$(SlowCheetah_NuGetImportPath)') ">$(SlowCheetah_NuGetImportPath)</SlowCheetahTargets>
  </PropertyGroup>

我注意到当PropertyGroup 高于所有ItemGroup`s ellements MsBuild.exe 终于做了改造

【讨论】:

  • 投票,不是因为这是我的答案,而是它指向了正确的地方。我必须更新我的 &lt;SlowCheetahTargets/&gt; 元素中的路径以匹配我的 SlowCheetah 文件的位置。构建服务器上的位置不同于我的机器上安装 SlowCheetah 时的默认位置。
【解决方案2】:

查找重复的 SlowCheetahTargets 部分 - 我有一个旧版本和一个新版本,旧版本指向 nuget 包目录中不再存在的位置。

删除旧的/重复的 SlowCheetahTargets 部分的整个属性组,这应该可以修复它。

【讨论】:

猜你喜欢
  • 2013-05-29
  • 2014-11-09
  • 2012-02-20
  • 2014-07-22
  • 2018-06-19
  • 2015-06-18
  • 2018-08-10
  • 2014-10-12
  • 1970-01-01
相关资源
最近更新 更多