xml SlowCheetah 在构建时不转换文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13500789/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SlowCheetah not transforming file on build
提问by Richard S.
I have a project I am trying to use SlowCheetah for. I have created my config file (Test.web.config) and all the transformations I want to use (Debug_Mock.config, Debug_SQL.config, Release) in my Build configuration I have a post-build event is supposed to copy the transformed file into another directory but the file cannot be found
我有一个项目正在尝试使用 SlowCheetah。我已经在我的构建配置中创建了我的配置文件 (Test.web.config) 和所有我想使用的转换 (Debug_Mock.config, Debug_SQL.config, Release) 我有一个构建后事件应该复制转换后的文件进入另一个目录,但找不到文件
(error xcopy exited with code 4)
(错误 xcopy 以代码 4 退出)
SlowCheetah doesn't seem to be transforming the file and placing it in the output directory (bin folder) like I would expect. Does anyone have any ideas as to why it is not happening, maybe a setting somewhere?
SlowCheetah 似乎并没有像我期望的那样转换文件并将其放置在输出目录(bin 文件夹)中。有没有人知道为什么它没有发生,也许是某个地方的设置?
FYI: This process works on another machine, with the same project. As far as I can tell the same set up as well. But I may not be looking in the correct place.
仅供参考:此过程适用于具有相同项目的另一台机器。据我所知,同样的设置也是如此。但我可能没有找对地方。
采纳答案by user1858286
Enable build verbosity (
Tools -> Options -> Projects and Solutions -> Build and Run) and see the difference between the version that is working and the one that is not.To my knowledge, slow-Cheetah supports config transforms for the
app.configfiles but notweb.configson debug at present. It should put a transformedweb.configfile in thebinfolder of your project but your project still reads from theconfig filein the root folder. Please have a look at pre/post build events at http://sedodream.com/CommentView,guid,68b7e248-b9f5-4d07-bdfe-eb037bcf2cbb.aspx.You can request for web config transform support on debug at
https://github.com/sayedihashimi/slow-cheetah/issues/39Try re-installing Slow-Cheetah.
启用构建详细程度 (
Tools -> Options -> Projects and Solutions -> Build and Run) 并查看正在运行的版本与未运行的版本之间的差异。据我所知,slow-Cheetah 支持
app.config文件的配置转换,但web.configs目前不支持调试。它应该将转换后的web.config文件放在bin您的项目文件夹中,但您的项目仍然从config file根文件夹中读取。请在http://sedodream.com/CommentView,guid,68b7e248-b9f5-4d07-bdfe-eb037bcf2cbb.aspx查看构建前/构建后事件 。您可以在https://github.com/sayedihashimi/slow-cheetah/issues/39在调试时请求 Web 配置转换支持
尝试重新安装Slow-Cheetah。
回答by laurencee
For me I found the issue was that the slow cheetah property group in the config file was below the section where it checked if it existed.
对我来说,我发现问题是配置文件中的慢速猎豹属性组低于它检查它是否存在的部分。
So the fix was simply to move the property group above that line somewhere which would allow the transform to run as expected.
因此,修复只是将属性组移动到该行上方的某个位置,这将允许转换按预期运行。
Put this:
把这个:
<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>
Above this:
以上:
<Import Project="$(SlowCheetahTargets)" Condition="Exists('$(SlowCheetahTargets)')" Label="SlowCheetah" />
回答by Thorsten Hüglin
Check in your Project, if there exists a folder named SlowCheetahcontaining the file SlowCheetah.Transforms.targets. If this file is missing, try the following steps:
检查您的项目,如果存在名为SlowCheetah的文件夹,其中包含文件SlowCheetah.Transforms.targets。如果此文件丢失,请尝试以下步骤:
- right click on solution
- "Manage NuGet Packages for Solution...", browse for SlowCheetah
- click on "Manage"
- deselect your project and click "Ok"
- click on "Manage" again
- select your project and click once more "Ok"
- 右键单击解决方案
- “Manage NuGet Packages for Solution...”,浏览SlowCheetah
- 点击“管理”
- 取消选择您的项目并单击“确定”
- 再次点击“管理”
- 选择您的项目并再次单击“确定”
This will recreate the missing file.
这将重新创建丢失的文件。
回答by Hink
After a reinstall as described above, I needed to add the subTypeand transformOnBuildnodes to my csproj file, and it started working for me.
如上所述重新安装后,我需要将subType和transformOnBuild节点添加到我的 csproj 文件中,它开始对我来说有效。
<None Include="App.config">
<SubType>Designer</SubType>
<TransformOnBuild>true</TransformOnBuild>
</None>
<None Include="App.QA.config">
<DependentUpon>App.config</DependentUpon>
<IsTransformFile>True</IsTransformFile>
</None>
回答by Frank Liu
Please Note, you have to install the SlowCheetah Visual studio extension ANDthe SlowCheetah nuget package for the project in question for the transformation to work.
请注意,您必须为相关项目安装 SlowCheetah Visual Studio 扩展和SlowCheetah nuget 包,以便转换工作。
回答by James Blake
With SlowCheetah 2.5.15 and Visual Studio 2015, I had to uninstall the nuget package and then manually remove the following from the relevant .csproj file:
使用 SlowCheetah 2.5.15 和 Visual Studio 2015,我必须卸载 nuget 包,然后从相关的 .csproj 文件中手动删除以下内容:
<Import Project="$(SlowCheetahTargets)" Condition="Exists('$(SlowCheetahTargets)')" Label="SlowCheetah" />
and
和
<PropertyGroup Label="SlowCheetah">
<SlowCheetahToolsPath>$([System.IO.Path]::GetFullPath( $(MSBuildProjectDirectory)\..\packages\SlowCheetah.2.5.15\tools\))</SlowCheetahToolsPath>
<SlowCheetah_EnableImportFromNuGet Condition=" '$(SlowCheetah_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>
Once this was done and the SlowCheetah nuget package was reinstalled, my problem was resolved.
完成此操作并重新安装 SlowCheetah nuget 软件包后,我的问题就解决了。
回答by Ken Smith
SlowCheetah 3.2.20 added a, uhh, "feature", designed to respect the "Do Not Copy" file setting in Visual Studio. So if you don't have your .config file set to "Copy Always" or "Copy if Newer", it won't copy them to the output folder.
SlowCheetah 3.2.20 添加了一个,呃,“功能”,旨在尊重 Visual Studio 中的“请勿复制”文件设置。因此,如果您没有将 .config 文件设置为“始终复制”或“如果较新则复制”,它不会将它们复制到输出文件夹。
See https://github.com/Microsoft/slow-cheetah/issues/182for some details.
有关详细信息,请参阅https://github.com/Microsoft/slow-cheetah/issues/182。
This was my issue - spent three hours debugging it...
这是我的问题 - 花了三个小时调试它......

