Msbuild 自动慢猎豹构建方法
我不想在所有构建服务器上安装Slow Cheetah 我们使用慢速Cheetah进行配置转换,它工作得非常好。它会生成多个app.config文件,我们会根据需要对其进行更改 我们已经安装了几个服务器。它们都有自己的代码库,它们从命令行中提取代码并相应地构建包。那些代码中有那些配置文件。但是,当我们从命令行编译应用程序时,如果没有安装slow cheetah,则不会通过转换生成包。否则就可以了 我们永远不知道何时安装新服务器和新用户,因此不可能在每个服务器和用户上都安装慢速cheetah 有没有可能在应用程序中使用慢速cheetah dll并从中手动调用转换方法Msbuild 自动慢猎豹构建方法,msbuild,build-process,build-automation,slowcheetah,config-transformation,Msbuild,Build Process,Build Automation,Slowcheetah,Config Transformation,我不想在所有构建服务器上安装Slow Cheetah 我们使用慢速Cheetah进行配置转换,它工作得非常好。它会生成多个app.config文件,我们会根据需要对其进行更改 我们已经安装了几个服务器。它们都有自己的代码库,它们从命令行中提取代码并相应地构建包。那些代码中有那些配置文件。但是,当我们从命令行编译应用程序时,如果没有安装slow cheetah,则不会通过转换生成包。否则就可以了 我们永远不知道何时安装新服务器和新用户,因此不可能在每个服务器和用户上都安装慢速cheetah 有没有
感谢我在应用程序中包括SlowCheetah,如下所示,以避免将其安装在构建解决方案的服务器上:
$(MSBuildProjectDirectory)\..\Tools\SlowCheetah\SlowCheetah.Transforms.targets
这是:
<Import Project="$(SlowCheetahTargets)" Condition="Exists('$(SlowCheetahTargets)')" />
…而且它似乎能很好地处理这项工作,即使在TeamCity构建/发布时也是如此
编辑:
当您将SlowCheetah安装到Visual Studio中后,您将发现在
%localappdata%\Microsoft\MSBuild\SlowCheetah\v1
(驱动器:\Users\yourusername\AppData\Local\Microsoft\MSBuild\SlowCheetah\v1
)中提到的两个文件,可以通过手动编辑项目文件来处理此功能。设置起来有点麻烦,但这确实意味着您不需要额外的DLL
在文本编辑器中打开项目文件。在项目文件的底部,即关闭标记之前,包括以下内容:
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterCompile" Condition="exists('app.$(Configuration).config')">
<!-- Generate transformed app config in the intermediate directory -->
<TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
<!-- Force build process to use the transformed configuration file from now on. -->
<ItemGroup>
<AppConfigWithTargetPath Remove="app.config" />
<AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
<TargetPath>$(TargetFileName).config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
</Target>
<ItemGroup>
<Content Include="App.config" />
<Content Include="App.Debug.config">
<DependentUpon>App.config</DependentUpon>
</Content>
<Content Include="App.Release.config">
<DependentUpon>App.config</DependentUpon>
</Content>
</ItemGroup>
$(TargetFileName).config
然后,在项目文件中找到该行并将其替换为以下内容:
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterCompile" Condition="exists('app.$(Configuration).config')">
<!-- Generate transformed app config in the intermediate directory -->
<TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
<!-- Force build process to use the transformed configuration file from now on. -->
<ItemGroup>
<AppConfigWithTargetPath Remove="app.config" />
<AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
<TargetPath>$(TargetFileName).config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
</Target>
<ItemGroup>
<Content Include="App.config" />
<Content Include="App.Debug.config">
<DependentUpon>App.config</DependentUpon>
</Content>
<Content Include="App.Release.config">
<DependentUpon>App.config</DependentUpon>
</Content>
</ItemGroup>
App.config
App.config
您需要为添加的每个配置添加一个额外的内容Include–不幸的是,使用此方法无法获得简单的“添加转换”上下文菜单
之后,在项目目录中创建文件,然后就可以开始了。它不像SlowCheetah那样流畅,但它确实可以让您的代码保持可移植性。这里定义了详细的分步过程
感谢最新版本的SlowCheetah(2.5.14)可在上获得。通过nuget添加时,它存储在本地解决方案目录中的
packages
文件夹中(与所有nuget软件包一样),这意味着它现在应该可以在任何现成的构建服务器上工作 你提到构建几个app.config文件——这可能就是我在寻找的吗?:-)什么是SlowCheetah.Transforms.Targets,请引导我。感谢实际将Microsoft.Web.Publishing.Tasks.dll作为任务插入意味着您必须在生成服务器上安装visual studio。此Dll仅随visual studio提供,而不随.NET framework本身提供。所以你关于“不需要额外的DLL”的说法是不正确的。注:据我所知,slowcheetah的创建正是为了解决这一限制——有具体的任务来转换configs\XML,但开发人员不允许使用它,除非与Visual Studio一起使用。我怀疑易卜拉欣·哈希米(Ibrahim Hashimi)之所以启动了slowcheetah,是因为他不知道TransformXml任务。如果.dll不存在,常规web项目如何在生成机器上使用配置转换进行编译?(我承认我对此有些无知;我一直在构建机器上安装VS。)我认为SlowCheetah开始简化流程——当然我上面描述的流程更麻烦。他们有吗?AFAIK-项目已编译,但未应用任何转换。是的,这就是为什么我们所有的构建代理都安装了VS的原因。实际上,VS对web.config转换的处理与对SlowCheetah的处理之间没有明显的区别。如果我错了,请纠正我,但是VS刚刚为web.configs锁定了此功能,它实际上适用于任何类型的xml文件。我使用此任务不仅转换azure ServiceDefinition和ServiceConfiguration,还生成构建时转换以在共享测试服务器上运行azure emulator实例-这是一项痛苦但可实现的任务web项目和SlowCheetah中的转换基本相同。是的,我知道TransformXml,我拥有它:)XDT可以用于任何XML文件,web项目只是对web.config有特定的支持。使用SlowCheetah,您不需要安装web项目。不适用于我,。您好,请您与我共享示例工作项目,因为当我在项目文件中执行相同操作并发布包(myweb.zip)时,我的app.config文件不会转换!!作为链接的说明,我还必须添加Microsoft.Web.XmlTransform.dll。