Jas*_*n H 3 c# azure azure-cloud-services visual-studio-2015 tfs-2015
我已经尝试了所有可能遇到的示例,但还无法完成其中的一项。有没有人设法使ServiceDefinition.csdef转换真正起作用?
在下面的每一次尝试中,我都使用Bin文件夹中的ServiceDefinition.csdef(在生成后),然后查看了包文件中的csdef。我将“基本”文件或原始文件中的vmsize设置为“其他”(我知道这不是实际大小),然后使用了一个转换,该转换应将其更改为“大”,但最终文件始终显示为“其他”。
还有大约三四个
我们建立基于Umbraco的网站并将其托管在Azure上。我们设置3个环境(QA,UAT和LIVE),并且在每个环境上我们都有2个Web角色(前端和后台)。转换ServiceDefinition.csdef的目标是使达到以下vmsize:
QA-FE:小型
QA-BO:小型
UAT-FE:小型
UAT-BO:小型
LIVE-FE:大型
LIVE-BO:小型
我还想指出,我曾尝试创建多个Cloud Service Project,但是正如您从上述要求可以看到的那样,这有点“奇怪”
最后,转换必须能够在我们的TFS Build Server(vNext)上进行。
在审查了许多不同的建议后,我想到了解决方案,我发现其中的某些部分有效,而其他则无效。我最终结合并简化了发现的工作。
对于此示例,我们具有以下要求:
转到Azure云服务的项目文件夹。复制ServiceDefinition.csdef并将其命名为ServiceDefinition.Base.csdef。添加3个文件ServiceDefinition.QA.csdef | ServiceDefinition.UAT.csdef | ServiceDefinition.LIVE.csdef在Visual Studio中卸载项目并编辑ccprog文件,找到包含ServiceDefinition.csdef的ItemGroup,其外观如下所示:
<ItemGroup>
<ServiceDefinition Include="ServiceDefinition.csdef" />
<ServiceConfiguration Include="ServiceConfiguration.QA.cscfg" />
<ServiceConfiguration Include="ServiceConfiguration.UAT.cscfg" />
<ServiceConfiguration Include="ServiceConfiguration.LIVE.cscfg" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
使它看起来像这样:
<ItemGroup>
<ServiceDefinition Include="ServiceDefinition.csdef" />
<ServiceConfiguration Include="ServiceConfiguration.QA.cscfg" />
<ServiceConfiguration Include="ServiceConfiguration.UAT.cscfg" />
<ServiceConfiguration Include="ServiceConfiguration.LIVE.cscfg" />
<None Include="ServiceDefinition.Base.csdef" />
<None Include="ServiceDefinition.QA.csdef">
<DependentUpon>ServiceDefinition.csdef</DependentUpon>
</None>
<None Include="ServiceDefinition.UAT.csdef">
<DependentUpon>ServiceDefinition.csdef</DependentUpon>
</None>
<None Include="ServiceDefinition.LIVE.csdef">
<DependentUpon>ServiceDefinition.csdef</DependentUpon>
</None>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
现在转到ccprog文件的底部和导入之间
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets" />
Run Code Online (Sandbox Code Playgroud)
和结束项目标签
</Project>
Run Code Online (Sandbox Code Playgroud)
添加以下内容:
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets" />
<Target Name="BeforeBuild" Condition=" '$(Configuration)' != 'Debug' ">
<Message Text="Removing Read-Only Attribute from ServiceDefinition.csdef" />
<Exec Command="attrib -r $(ProjectDir)ServiceDefinition.csdef" />
<Message Text="Transforming ServiceDefinition.Base.csdef with ServiceDefinition.$(Configuration).csdef to create ServiceDefinition.csdef" />
<TransformXml Source="ServiceDefinition.Base.csdef" Transform="ServiceDefinition.$(Configuration).csdef" Destination="ServiceDefinition.csdef" />
</Target>
Run Code Online (Sandbox Code Playgroud)
保存并重新加载项目,如果出现任何错误消息,请更正此问题。重新加载后,您的项目文件应如下所示:
打开ServiceDefinition.QA.csdef并添加以下内容:
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="AzureCloudTransform" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" schemaVersion="2015-04.2.6">
<WebRole name="WebApplication" vmsize="Small" xdt:Transform="SetAttributes" xdt:Locator="Match(name)">
</WebRole>
</ServiceDefinition>
Run Code Online (Sandbox Code Playgroud)
保存
打开ServiceDefinition.UAT.csdef并添加以下内容:
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="AzureCloudTransform" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" schemaVersion="2015-04.2.6">
<WebRole name="WebApplication" vmsize="Large" xdt:Transform="SetAttributes" xdt:Locator="Match(name)">
</WebRole>
</ServiceDefinition>
Run Code Online (Sandbox Code Playgroud)
保存
打开ServiceDefinition.LIVE.csdef并添加以下内容:
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="AzureCloudTransform" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" schemaVersion="2015-04.2.6">
<WebRole name="WebApplication" vmsize="XLarge" xdt:Transform="SetAttributes" xdt:Locator="Match(name)">
</WebRole>
</ServiceDefinition>
Run Code Online (Sandbox Code Playgroud)
保存
做完了
现在,当您在其中一种“构建配置”中进行构建时,转换将在构建之前进行,然后允许VS正常运行以打包文件。ServiceDefinition.csdef文件将在构建之前更改,并正确包含在软件包中。我选择以这种方式进行转换的最大原因是,它可以在使用vNext构建定义的构建服务器上运行。