如何修改在cspkg定义的csdef [英] How to modify the csdef defined in a cspkg

查看:368
本文介绍了如何修改在cspkg定义的csdef的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要部署到不同的环境,蔚蓝我修改csdef作为编译步骤来更改主机头的一部分。这样做需要为每个环境一旦建立cspkg,而不是能够重用cspkg和部署指定不同的configs。

To deploy to different azure environments I modify the csdef as part of the compilation step to change the host headers. Doing so requires building the cspkg once for each environment instead of being able to reuse the cspkg and specify different configs for deployment.

我想,而不是修改cspkg的csdef文件在创建后,无需重新编译。这是可能的,如果又如何?

I would like to instead modify the csdef file of a cspkg after it has been created, without recompiling. Is that possible, and if so how?

推荐答案

我做过类似你以后测试和现场环境区分的东西。首先你需要创建一个你想用你的备用设置一个新的.csdef文件。这需要完整的文件,我们只是要与原来的换出来。现在,我们需要把它添加到云项目。右键单击云项目,并选择卸载项目。再次右键单击它并选择编辑[项目名称]。还有,看起来有点像这样的内容:

I've done something similar to what you're after to differentiate between test and live environments. First of all you need to create a new .csdef file that you want to use for your alternate settings. This needs to be the complete file as we're just going to swap it out with the original one. Now we need to add this to the cloud project. Right click on the cloud project and select unload project. Right click on it again and select Edit [Name of project]. There's a section that looks a bit like this:

<ItemGroup>
    <ServiceConfiguration Include="ServiceConfiguration.Test.cscfg" />
    <ServiceDefinition Include="ServiceDefinition.csdef" />
    <ServiceConfiguration Include="ServiceConfiguration.cscfg" />
</ItemGroup>

添加一个指向新创建的文件的新ServiceDefinition项目。现在,找到以下行:

Add a new ServiceDefinition item that points to your newly created file. Now find the following line:

<Import Project="$(CloudExtensionsDir)Microsoft.WindowsAzure.targets" />

然后添加此code座,编辑TargeProfile检查是你想用你的替代,并确保它指向您的新.csdef文件的生成配置

Then add this code block, editing the TargeProfile check to be the build configuration you're wanting to use for your alternate and ensuring that it points to your new .csdef file

<Target Name="AfterResolveServiceModel">
    <!-- This should be run after it has figured out which definition file to use
        but before it's done anything with it.  This is all a bit hard coded, but
        basically it should remove everything from the SourceServiceDefinition
        item and replace it with the one we want if this is a build for test-->
    <ItemGroup>
      <!-- This is an interesting way of saying remove everything that is in me from me-->
      <SourceServiceDefinition Remove="@(SourceServiceDefinition)" />
      <TargetServiceDefinition Remove="@(TargetServiceDefinition)" />
    </ItemGroup>
    <ItemGroup Condition="'$(TargetProfile)' == 'Test'">
      <SourceServiceDefinition Include="ServiceDefinition.Test.csdef" />
    </ItemGroup>
    <ItemGroup Condition="'$(TargetProfile)' != 'Test'">
      <SourceServiceDefinition Include="ServiceDefinition.csdef" />
    </ItemGroup>
    <ItemGroup>
      <TargetServiceDefinition Include="@(SourceServiceDefinition->'%(RecursiveDirectory)%(Filename).build%(Extension)')" />
    </ItemGroup>
    <Message Text="Source Service Definition Changed To Be: @(SourceServiceDefinition)" />
  </Target>

要恢复正常,请右键单击该项目并选择刷新项目。现在,当你建立你的项目,这取决于你使用的配置,它会用不同的.csdef文件。值得注意的是,在设置编辑器是不知道你的第二个.csdef文件的,所以如果你通过GUI添加任何新的设置,您将需要手动将它们添加到这个备用版本。

To go back to normal, right click on the project and select Reload Project. Now when you build your project, depending on which configuration you use, it will use different .csdef files. It's worth noting that the settings editor in is not aware of your second .csdef file so if you add any new settings through the GUI you will need to add them manually to this alternate version.

这篇关于如何修改在cspkg定义的csdef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆