【发布时间】:2014-07-23 09:09:50
【问题描述】:
我希望 Azure 包文件成为成功签入构建的输出。我们希望能够从放置位置将这些包发布到 Azure。
根据this post,我们只需要csdef文件就可以在命令行中使用cspack创建包文件:
cspack “c:\<path to the csdeffile>\servicedefinition.csdef” /role:<Name of the role as defined in the csdef file>;<location of the binaries> /sites:<Name of the role>;<name of the site path>;<location of the website files>
但我想避免使用命令行。我知道有一个可以使用的CSPack 任务,但我一直在努力寻找有关它的更多信息。我在网上找不到任何规范,期待this Stackoverflow post 上的一些信息。
如何将上面的 cspack 命令翻译成 CSPack 构建任务?
我根据MSDN spec for cspack.exe 得出以下结论,但我不得不做出很多假设:
<PropertyGroup>
<VisualStudioVersion Condition=" '$(VisualStudioVersion)' == '' ">10.0</VisualStudioVersion>
<CloudExtensionsDir Condition=" '$(CloudExtensionsDir)' == '' ">$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Windows Azure Tools\2.2\</CloudExtensionsDir>
<Roles></Roles>
</PropertyGroup>
<Import Project="$(CloudExtensionsDir)Microsoft.WindowsAzure.targets" />
<Target Name="CreatePackage" DependsOnTargets="Build">
<CSPack
ServiceDefinitionFile="MyCloudProject\ServiceDefinition.csdef"
Output="$(OutDir)Publish\$(ProjectName).cspkg"
PackRoles="MyRoleName"
SiteMapping="MyRoleName;MySiteName;MySitePath"
RoleProperties="MyRoleName;$(OutDir)Publish\MyProject.dll"
CopyOnly="false">
</CSPack>
</Target>
我收到以下构建错误:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Windows Azure 工具\2.2\Microsoft.WindowsAzure.targets (351):无默认值 服务配置“ServiceConfiguration.cscfg”可以在 项目。
说实话,我真的不知道自己在做什么。我已经有一段时间了,所以任何指导将不胜感激。
复制 cspkg 文件将是 easy enough,但我似乎无法弄清楚如何执行打包。
我们正在使用 Visual Studio Online(基于云的 TFS)。
编辑:
我们确实有云项目。这就是我们发布的方式(右键单击 -> 发布)。这显然并不理想,因为它没有遵循“一次构建”的策略,并且会在更大的团队中增加更多的复杂性。
@Simon Opelt:使用CorePublish 目标是否需要更改构建定义?现在,构建定义使用特定的 .build 文件(为了执行 NuGet 恢复),然后运行解决方案中所有项目的构建目标:
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutDir>$(MSBuildThisFileDirectory)bin</OutDir>
<Configuration>Release</Configuration>
<ProjectProperties>OutDir=$(OutDir);Configuration=$(Configuration);</ProjectProperties>
</PropertyGroup>
<ItemGroup>
<Solution Include="$(MSBuildThisFileDirectory)*.sln" />
</ItemGroup>
<Target Name="RestorePackages">
<Exec Command=""$(MSBuildThisFileDirectory).nuget\NuGet.exe" restore "%(Solution.Identity)"" />
</Target>
<Target Name="Clean">
<MSBuild Targets="Clean" Projects="@(Solution)" Properties="$(ProjectProperties)" />
</Target>
<Target Name="Build" DependsOnTargets="RestorePackages">
<MSBuild Targets="Build" Projects="@(Solution)" Properties="$(ProjectProperties)" />
</Target>
<Target Name="Rebuild" DependsOnTargets="RestorePackages">
<MSBuild Targets="Rebuild" Projects="@(Solution)" Properties="$(ProjectProperties)" />
</Target>
</Project>
这也构建和运行我们的测试项目。将云项目与 CorePublish 结合使用是否仍然允许这样做?
【问题讨论】:
-
您在使用云项目吗?这是一个选项还是你想坚持使用 web-projects 和 csdef/cscfg?您是否考虑过使用 blog.ehuna.org/2011/02/how_to_automate_the_creation_o.html 中描述的 MSBuild CorePublish 目标?
-
@SimonOpelt:问题已编辑。谢谢!
标签: .net azure tfs msbuild azure-web-roles