2011-09-15 8 views
18

私は自分の製品のWebサイトをパッケージ化して配布するためにWeb Deployを使用しています。特に、このソリューションを展開するために私のソリューションには2つの異なるプロジェクトがあります。MsBuildを使用してカスタマイズされたMsDeployマニフェストを生成する(パッケージターゲット)

解決策(Windowsサービス)の3番目のプロジェクトもWebサーバーにインストールする必要があります。

カスタムマニフェスト(dirPathfilePathrunCommandプロバイダ用)を作成し、MsDeployを直接呼び出して展開することができます。しかし、可能であれば、既存のMsBuildタスクを利用してサービスをパッケージ化したいと考えています。

は、私はMSBuildの目標を経由して、マニフェストファイルのいくつかのカスタマイズを行うことが可能です参照してください。

http://social.msdn.microsoft.com/Forums/en/msbuild/thread/1044058c-f762-456b-8a68-b0863027ce47

特にMsDeploySourceManifestアイテムを使用することによって。

Packageターゲットを使用すると、適切な.targetsファイルを突き刺した後、contentPathまたはiisAppがマニフェストに追加されるように見えます。理想的には、アセンブリ(またはディレクトリ)をコピーし、おそらくACLを設定して、サービスでinstallutil.exeを実行するだけです。

私のcsprojファイルを編集してPackageターゲットで生成されたマニフェストを完全にカスタマイズすることはできますか?

もしそうでなければ、Packageに相当する新しいターゲットを作成する簡単な方法はありますか?しかし、私は完全なカスタムマニフェストを吐き出すことができますか?

+0

これに答えましたか? – musica

+0

@Graci:やったよ。私は今週中にこれについて作業項目を終えています。すべての作業が終わったら回答を投稿します。主なコンセプトは、カスタムの '.targets'ファイルを作成し、カスタムターゲットを使用してrunCommandのプロバイダエントリを追加してカスタムバッチファイルを実行します(サービスの停止/アンインストール、インストール/起動)。 xmlファイルをプロジェクトに追加し、 'IncludeIisSettingsOnPublish = False'や' IncludeIisSettingsOnPublish = False'などの特定のフラグを設定します。ああ、無料のSlowCheetah以外のWebトランスフォームの拡張も役に立ちました。 –

+0

@Merlyn:あなたのソリューションを共有する時間を見つけたら、それはあなたがそれをうまくカバーしているようにあなたの最後のコメントから偉大になるでしょう。 –

答えて

16

私はこの記事の仕組みを学びたいと思っている人にはまだ完全には書いていませんが、少なくともこの目標を達成する方法を書くようになっています。

http://thehappypath.net/2011/11/21/using-msdeploy-for-windows-services/

編集:リンクは今のために死んでいるあなたが興味があるなら、私に教えてください、私は他の場所でそれを投稿することができます。)。

私のガイドでは、これらの全体的な手順を経る:

  • サービスは(重要ではないが、対処しやすい)インストール時に自身を起動することを確認し
  • プロジェクトにMicrosoft.WebApplication.targetsファイルを追加し、あなたがウェブプロジェクトを持っていなくても。これにより、Package MsBuildターゲットが有効になります。
  • 変更をサポートするためにParameters.xmlファイルを追加します
  • マニフェストカスタムのMSBuildパッケージは/アンインストールを停止し、サービス
  • をインストールするには、プロジェクトにいくつかのバッチスクリプトを追加構築するプロジェクトにカスタム.targetsファイルを追加します。ターゲット展開ディレクトリをもう少し簡単に変更できます。
  • セットアップアプリ。

    msbuild MyProject.csproj /t:Package /p:Configuration=Debug 
    

    をあなたは、このコマンドラインで結果のパッケージを展開することができます:あなたは、このコマンドラインを使用してプロジェクトをパッケージ化することができますthe SlowCheetah Visual Studio addon

を使用してコンフィグ変換

MyService.Deploy.cmd /Y /M:mywebserver -allowUntrusted 

最も文書化されていない部分(私のガイドを除いて)カスタムマニフェストを作成しています。私の現在のファイルをダンプしています(まだ少しバグがありますが、修正できます - MsDeploy remoting executing manifest twiceを参照してください)runCommandのダイレクトバッチファイルのみを使用してください。

<?xml version="1.0" encoding="utf-8"?> 
<Project ToolsVersion="4.0" DefaultTargets="Build" 
     xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
    <!-- This file must be included before Microsoft.Web.Publishing.targets so we can hook into BeforeAddIisSettingAndFileContentsToSourceManifest --> 

    <PropertyGroup> 

    <!-- Include our targets --> 
    <IncludeStopServiceCommand>True</IncludeStopServiceCommand> 
    <IncludeSetCustomAclsProvider>True</IncludeSetCustomAclsProvider> 
    <IncludeInstallServiceCommand>True</IncludeInstallServiceCommand> 
    <IncludeMoveAppConfigToCorrectPackagePath>True</IncludeMoveAppConfigToCorrectPackagePath> 

    <!-- Uncomment to enable more verbose MsBuild logging --> 
    <!-- <EnablePackageProcessLoggingAndAssert>True</EnablePackageProcessLoggingAndAssert> --> 

    <!-- Enable web.config transform, but hack it to work for app.config --> 
    <ProjectConfigFileName>app.config</ProjectConfigFileName> 
    <TransformWebConfigEnabled>True</TransformWebConfigEnabled> 
    <UseParameterizeToTransformWebConfig>True</UseParameterizeToTransformWebConfig> 

    <!-- Enable web project packaging, but hack it to work for non-web app --> 
    <DeployAsIisApp>False</DeployAsIisApp> 
    <IncludeIisSettingsOnPublish>False</IncludeIisSettingsOnPublish> 
    <IncludeSetAclProviderOnDestination>False</IncludeSetAclProviderOnDestination> 
    <DisableAllVSGeneratedMSDeployParameter>True</DisableAllVSGeneratedMSDeployParameter> 

    <!-- Insert our custom targets into correct places in build process --> 
    <BeforeAddIisSettingAndFileContentsToSourceManifest Condition="'$(BeforeAddIisSettingAndFileContentsToSourceManifest)'==''"> 
     $(BeforeAddIisSettingAndFileContentsToSourceManifest); 
     AddStopServiceCommand; 
    </BeforeAddIisSettingAndFileContentsToSourceManifest> 

    <AfterAddIisSettingAndFileContentsToSourceManifest Condition="'$(AfterAddIisSettingAndFileContentsToSourceManifest)'==''"> 
     $(AfterAddIisSettingAndFileContentsToSourceManifest); 
     AddSetCustomAclsProvider; 
     AddInstallServiceCommand; 
    </AfterAddIisSettingAndFileContentsToSourceManifest> 

    <OnAfterCopyAllFilesToSingleFolderForPackage Condition="'$(OnAfterCopyAllFilesToSingleFolderForPackage)'==''"> 
     $(OnAfterCopyAllFilesToSingleFolderForPackage); 
     MoveAppConfigToCorrectPackagePath; 
    </OnAfterCopyAllFilesToSingleFolderForPackage> 

    </PropertyGroup> 

    <!-- Custom targets --> 
    <Target Name="AddStopServiceCommand" Condition="'$(IncludeStopServiceCommand)'=='true'"> 
    <Message Text="Adding runCommand to stop the running Service" /> 
    <ItemGroup> 

     <MsDeploySourceManifest Include="runCommand"> 
     <path>$(_MSDeployDirPath_FullPath)\bin\servicestop.bat</path> 
     <waitInterval>20000</waitInterval> 
     <AdditionalProviderSettings>waitInterval</AdditionalProviderSettings> 
     </MsDeploySourceManifest> 

    </ItemGroup> 
    </Target> 

    <Target Name="AddSetCustomAclsProvider" Condition="'$(IncludeSetCustomAclsProvider)'=='true'"> 
    <ItemGroup> 

     <MsDeploySourceManifest Include="setAcl"> 
     <Path>$(_MSDeployDirPath_FullPath)</Path> 
     <setAclUser>LocalService</setAclUser> 
     <setAclAccess>FullControl</setAclAccess> <!-- Todo: Reduce these permissions --> 
     <setAclResourceType>Directory</setAclResourceType> 
     <AdditionalProviderSettings>setAclUser;setAclAccess;setAclResourceType</AdditionalProviderSettings> 
     </MsDeploySourceManifest> 

    </ItemGroup> 
    </Target> 

    <Target Name="AddInstallServiceCommand" Condition="'$(IncludeInstallServiceCommand)'=='true'"> 
    <Message Text="Adding runCommand to install the Service" /> 
    <ItemGroup> 

     <MsDeploySourceManifest Include="runCommand"> 
     <path>cmd.exe /c $(_MSDeployDirPath_FullPath)\bin\serviceinstall.bat</path> 
     <waitInterval>20000</waitInterval> 
     <dontUseCommandExe>false</dontUseCommandExe> 
     <AdditionalProviderSettings>waitInterval;dontUseCommandExe</AdditionalProviderSettings> 
     </MsDeploySourceManifest> 

    </ItemGroup> 
    </Target> 

    <Target Name="MoveAppConfigToCorrectPackagePath" 
      Condition="'$(IncludeMoveAppConfigToCorrectPackagePath)'=='true'"> 
    <PropertyGroup> 
     <OriginalAppConfigFilename>$(_PackageTempDir)\App.Config</OriginalAppConfigFilename> 
     <TargetAppConfigFilename>$(_PackageTempDir)\bin\$(TargetFileName).config</TargetAppConfigFilename> 
    </PropertyGroup> 

    <Copy SourceFiles="$(OriginalAppConfigFilename)" DestinationFiles="$(TargetAppConfigFilename)" 
      Condition="Exists($(OriginalAppConfigFilename))" /> 
    <Delete Files="$(OriginalAppConfigFilename)" 
      Condition="Exists($(OriginalAppConfigFilename))" /> 
    </Target> 

</Project> 
+0

なぜあなたは、以前にあなたが空であると主張しているときに、ステップにそれらの元の値を記載していますか?それは本当にかわいい何かのためにneedeですか?つまり、いくつかのプロパティは ' $(prop);のように見えます。拡張子は 'なので、「設定されていない場合は使用する」と「上書きしない」の両方が使用されます。あなたのサンプルは、既に他のものが接続されていない場合にのみ自己付着し、同時に元の内容(その前に空であると仮定)を保存しようとします。私は、その条件、または 'concat'のふるまいが必要ではないと思います。 – quetzalcoatl

+0

とにかく、素晴らしい仕事!私はちょうどあなたのスニペットを見つける前に、同様のパッチ/拡張機能に来たので、おそらくそれが唯一の方法です。 Btw。私は 'TransformWebConfigEnabled'がデフォルトで' true'を持つことも発見しました。おそらくそれも調整できます。 Btw2。 app.configのパラメータ化を試してみましたか? 'webconfig/appconfig'が移動され、名前が変更されたために' SetParameters.xml'から値を適用することに問題はありませんか? – quetzalcoatl

+0

Hm ..はい、パッケージ内の 'parameters.xml'に古い 'App.config'がはっきりと参照されているので、問題はあるでしょう。私は、 'ImportParametersFiles'ターゲット、またはその近くにいくつかの追加の修正が必要だと思います。 – quetzalcoatl

関連する問題