コマンドラインからWindowsAzureクラウドプロジェクトをパッケージ化できますが、WindowsAzure自体に展開することはできません

icelava

WindowsAzureクラウドサービスのWebロールとして指定されたWebアプリケーションプロジェクトを特徴とするソリューションがあります。また、クラウドサービスのみを対象としたクラウドサービスプロジェクト(本番スロット)もあります。

SlnRoot \ WebApp1 \ WebApp1.csproj SlnRoot \ CloudDeployment \ CloudServiceName \ CloudServiceName.ccproj

Visual Studioからの公開(デプロイ)は非常に簡単です。クラウドプロジェクトのコンテキストメニューから[公開...]オプションを選択し、事前に構成されたすべてのクラウドサービス設定で[公開]をクリックするだけです。

現在、このプロセスを自動化するためのさらなるステップを実行しているので、VisualStudioを使用せずにコマンドラインと生のMSBuildから試してみます。

.nuget\nuget.exe restore
msbuild .\CloudDeployment\CloudServiceName\CloudServiceName.ccproj /t:Publish /p:PublishDir=..\..\pubout\ /fl1 /v:d

ただし、公開ターゲットは実際にはVisual Studioのパッケージオプションであり、WindowsAzureポータルに手動でアップロードする必要があるcspkgファイルのみを生成しているようです。もちろん、これではうまくいきません。Visual Studioが非常に簡単に実行できる追加の手順を実行するために指定する別のターゲットはありますか(展開ではありません。そのようなターゲットはありません)。

icelava

アドバイスありがとうございます。ただし、私の知識のギャップに対する真の答えは、MSBuildとPowerShellが最初にどのように連携するかということですが、すべてを連携させるためにカスタムMSBuildプロジェクトファイルを作成した同僚から来ました。基本的なサンプルはコメント付きで続きます

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0"
         DefaultTargets="Build"
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<!-- Declare configuration properties for this deployment -->
<!-- This custom.proj file is in a sub-directory in solution root -->

  <PropertyGroup>
    <SolutionDir Condition=" '$(SolutionDir)'=='' ">$(MSBuildThisFileDirectory)..\</SolutionDir>
    <SolutionPath Condition=" '$(SolutionPath)'=='' ">$(MSBuildThisFileDirectory)..\CloudService.sln</SolutionPath>
    <OutDir Condition=" '$(OutDir)'=='' ">$(MSBuildThisFileDirectory)\Output\Binaries\</OutDir>
    <PackageOutDir>$(MSBuildThisFileDirectory)Output\Packages\</PackageOutDir>
    <TargetCloudService>targetcloudservice</TargetCloudService>
    <DeployConfig>BuildConfig</DeployConfig>
    <PubSettingsPath>$(MSBuildThisFileDirectory)subscription.publishsettings</PubSettingsPath>
    <SubscriptionName>subscription name</SubscriptionName>
    <StorageAccount>targetstorageaccount</StorageAccount>
  </PropertyGroup>


<!-- Target to restore all Nuget packages on a clean repo pull. -->

  <Target Name="RestorePackages">
    <Message Text="Restoring nuget..."/>
    <Exec Command="&quot;$(SolutionDir).nuget\NuGet.exe&quot; restore &quot;$(SolutionPath)&quot;" />
  </Target>

<!--
Target to package the indicated cloud project,
which will build the referenced web role project first with desired build config.
-->

  <Target Name="PackageCloud" DependsOnTargets="RestorePackages">
    <Message Text="Creating package for cloud deployment ..."/>
    <MSBuild
      Projects="$(MSBuildThisFileDirectory)..\CloudDeployment\$(TargetCloudService)\$(TargetCloudService).ccproj"
      Properties="OutputPath=$(PackageOutDir)$(TargetCloudService)\;Configuration=$(DeployConfig);"
      Targets="Publish"/>
  </Target>


<!--
Target to deploy the package produced by the dependency target.
This is the part that launches PowerShell to execute custom ps1 script
with all the cloud service parameters (MSBuild variables above)
and cspkg package for deployment.
The custom script uses the Azure module cmdlets to make service checks and publish.
-->

  <Target Name="DeployCloud" DependsOnTargets="PackageCloud">
    <Message Text="Deploying package to cloud service ..."/>
    <Exec WorkingDirectory="$(MSBuildThisFileDirectory)"
         Command="$(windir)\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy ByPass -f $(MSBuildThisFileDirectory)PublishCloudService.ps1 -packageLocation &quot;$(PackageOutDir)$(TargetCloudService)\app.publish\$(TargetCloudService).cspkg&quot; -cloudConfigLocation &quot;$(PackageOutDir)$(TargetCloudService)\app.publish\ServiceConfiguration.Cloud.cscfg&quot; -subscriptionDataFile &quot;$(PubSettingsPath)&quot; -selectedsubscription &quot;$(SubscriptionName)&quot; -servicename $(TargetCloudService) -storageAccountName $(StorageAccount)" />
  </Target>
</Project>

したがって、ワンショットデプロイメントの呼び出しは次のようになります。

msbuild.exe custom.proj /t:DeployCloud

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ