首页 文章

自动慢速猎豹构建方法

提问于
浏览
9

我不想在所有构建服务器上安装Slow Cheetah .

我们正在使用Slow Cheetah进行配置转换,它工作得很好 . 它会生成多个app.config文件,我们会根据需要对它们进行更改 .

我们设置了几台服务器 . 所有这些都有他们的代码库,他们从命令行中提取代码并相应地构建包 . 这些代码中包含那些配置文件 . 但是当我们从命令行编译应用程序时,如果没有安装慢速猎豹,则不会使用转换生成包 . 否则它工作正常 .

我们永远都不知道我们何时设置新服务器和新用户,因此无法在每个服务器上安装慢速猎豹

有可能以某种方式在应用程序中使用慢速猎豹dll并从中手动调用转换方法?

谢谢

4 回答

  • 17
  • 4

    作为SlowCheetah的替代方案,可以通过手动编辑项目文件来处理此功能 . 设置起来有点麻烦,但它确实意味着您不需要额外的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>
    

    您需要为添加的每个配置添加额外的内容包含 - 遗憾的是,使用此方法您无法获得简单的“添加转换”上下文菜单 .

    之后就是在项目目录中创建文件的情况,然后你就可以开始了 . 它不像SlowCheetah那样光滑,但它确保您的代码可移植 .

  • 10

    我在应用程序中包含SlowCheetah,如下所示,以避免在构建解决方案的服务器上安装它:

    • 在我的解决方案根目录中,我有一个文件夹工具,其中包含(其中包括)SlowCheetah

    • myProject / Tools / SlowCheetah / SlowCheetah.Tasks.dll

    • myProject / Tools / SlowCheetah / SlowCheetah.Transforms.targets

    • 在(web-)应用程序项目的.csproj文件中,我有:

    <PropertyGroup>
              <SlowCheetahTargets Condition=" '$(SlowCheetahTargets)'=='' ">$(MSBuildProjectDirectory)\..\Tools\SlowCheetah\SlowCheetah.Transforms.targets  </SlowCheetahTargets>
       </PropertyGroup>
    

    还有这个:

    <Import Project="$(SlowCheetahTargets)" Condition="Exists('$(SlowCheetahTargets)')" />
    

    ..即使在从TeamCity构建/发布时,它似乎也很好地处理了这项工作 .

    编辑:

    在将SlowCheetah安装到Visual Studio中后,您将找到 %localappdata%\Microsoft\MSBuild\SlowCheetah\v1drive:\Users\yourusername\AppData\Local\Microsoft\MSBuild\SlowCheetah\v1 )中提到的两个文件 .

  • 4

    最新版本的SlowCheetah(2.5.14)可在Nuget上找到 . 通过nuget添加时,它存储在本地解决方案目录中的 packages 文件夹中(与所有nuget包一样),这意味着它现在可以在任何构建服务器上运行 .

相关问题