从命令行打包Azure Cloud Service,就像在Visual Studio中完成一样

时间:2016-08-04 13:55:15

标签: visual-studio azure msbuild azure-cloud-services stylecop

我想创建一个.cspkg文件,将我现有的Web应用程序部署为azure云服务。 Visual Studio(2015)在我设置的Cloud Service的上下文菜单中有这个漂亮的按钮:

VS Cloud Service Package Command

此按钮完全符合我的要求。它打包我的应用程序,以便我以后可以部署它。但我必须让它在我的构建代理上工作,所以我必须从命令行或PowerShell触发它。我尝试了以下在互联网上找到的命令

msbuild ProjectName.ccproj /t:Publish /p:Configuration=Cloud-Test  /p:SkipInvalidConfigurations=true /p:OutputPath=bin\ /p:PublishDir=bin\app

它通常有效,但我从我使用的StyleCop.Analyzers中得到了奇怪的错误。但是,通过Visual Studio打包时,我没有相同的错误。

所以这是我的问题:当我按下包裹按钮时,有谁知道Visual Studio在后台完全做了什么?

他们如何创建.cspkg,我可以从命令行/ powershell执行相同的操作吗?

编辑:

根据要求,以下是我正在尝试构建的.ccproj文件。我只更改了项目名称和隐私参考,并取出了我没有使用的配置:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>2.9</ProductVersion>
    <ProjectGuid>{ade99ccd-7432-4939-b3cd-69a736c0801b}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>Test.Cloud</RootNamespace>
    <AssemblyName>Test.Cloud</AssemblyName>
    <StartDevelopmentStorage>True</StartDevelopmentStorage>
    <Name>Test.Cloud</Name>
    <SccProjectName>SAK</SccProjectName>
    <SccProvider>SAK</SccProvider>
    <SccAuxPath>SAK</SccAuxPath>
    <SccLocalPath>SAK</SccLocalPath>
    <UseIISExpressByDefault>False</UseIISExpressByDefault>
    <PackageEnableRemoteDebugger>False</PackageEnableRemoteDebugger>
    <UseEmulatorExpressByDefault>False</UseEmulatorExpressByDefault>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)' == 'Cloud-Test' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Cloud-Test\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <!-- Items for the project -->
  <ItemGroup>
    <ServiceDefinition Include="ServiceDefinition.csdef" />
    <None Include="ServiceDefinition_Cloud-Prod.csdef">
      <DependentUpon>ServiceDefinition.csdef</DependentUpon>
    </None>
    <None Include="ServiceDefinition_Cloud-Test.csdef">
      <DependentUpon>ServiceDefinition.csdef</DependentUpon>
    </None>
    <ServiceConfiguration Include="ServiceConfiguration.Cloud-Prod.cscfg" />
    <ServiceConfiguration Include="ServiceConfiguration.Local.cscfg" />
    <ServiceConfiguration Include="ServiceConfiguration.Cloud-Test.cscfg" />
  </ItemGroup>
  <ItemGroup>
    <Folder Include="Profiles" />
  </ItemGroup>
  <ItemGroup>
    <PublishProfile Include="Profiles\TestlinieStaging.azurePubxml" />
    <PublishProfile Include="Profiles\PrototypProduction.azurePubxml" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="Test.csproj">
      <Name>Test</Name>
      <Project>{b9e789aa-89a4-48c0-ac61-113085533066}</Project>
      <Private>True</Private>
      <RoleType>Web</RoleType>
      <RoleName>Test</RoleName>
      <UpdateDiagnosticsConnectionStringOnPublish>True</UpdateDiagnosticsConnectionStringOnPublish>
    </ProjectReference>
  </ItemGroup>
  <!-- Import the target files for this project template -->
  <PropertyGroup>
    <VisualStudioVersion Condition=" '$(VisualStudioVersion)' == '' ">11.0</VisualStudioVersion>
    <CloudExtensionsDir Condition=" '$(CloudExtensionsDir)' == '' ">$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Windows Azure Tools\2.9\</CloudExtensionsDir>
  </PropertyGroup>
  <Import Project="$(CloudExtensionsDir)Microsoft.WindowsAzure.targets" />
  <PropertyGroup>
    <RoleName>Yello.Web.Site</RoleName>
  </PropertyGroup>
  <PropertyGroup Condition="$(Configuration)=='Cloud-Test'">
    <TargetProfile>Cloud-Test</TargetProfile>
  </PropertyGroup>
  <PropertyGroup>
    <PreBuildEvent>if exist "$(ProjectDir)ServiceDefinition_$(ConfigurationName).csdef" "$(VS120COMNTOOLS)..\IDE\tf.exe" checkout "$(ProjectDir)ServiceDefinition.csdef"
if exist "$(ProjectDir)ServiceDefinition_$(ConfigurationName).csdef" xcopy /Y "$(ProjectDir)ServiceDefinition_$(ConfigurationName).csdef" "$(ProjectDir)ServiceDefinition.csdef"</PreBuildEvent>
  </PropertyGroup>
</Project>

我确认上述配置仍然存在问题。我顺便使用msbuild 14.0.25420.1。

对于StyleCop分析仪。我在我试图打包的“测试”项目中激活它们。他们使用与我修改的CodeAnalysis相同的规则集文件。具体来说,我停用了规则SA1027UseTabsCorrectly。我非常有信心我正确地停用了它,因为它不再出现在我的情况下了。我正在使用StyleCop Analyzers Version 1.0.0。

0 个答案:

没有答案