2012-03-27 9 views
3

私は現在、数多くのWebサイトが含まれている再プラットフォームプロジェクトに取り組んでいます。すべて共通のヘッダーを使用しています。これらのサイトのいくつかはすべて同じマシン上にあったため、シンボリックリンクはすべて同じコンテンツを参照できるように設定されていました。特定の他のサイトが外部であったため、一般的な「includes.company.com」がセットアップされて利用されました。Visual Studio 2010ポストビルドイベント:現在のFlavorToBuildを渡す

今日まで早送りしています。私は、 "includes.company.com"サイトをVisual Studioにセットアップしようとしています。内容は簡単です。私は1つのHTMLファイルと1つのCSSファイルをすべての必要な画像と共に煮詰めました。

私が現在達成しようとしているのは、外部サイトから参照できる適切なリンクでHTMLとCSSを出力するための現在のビルド構成に基づいています。

私は現在pbuild.ps1が

param ([string]$config, [string]$target) 

If ($config -eq "Debug") 
{ 
    (get-content $target\common\css\stylesheet.min.css) -replace '{SERVER}', 'http://dev.includes.company.com' | set-content $target\Builds\$config\common\css\stylesheet.min.css 
    (get-content $target\header.html) -replace '{SERVER}', 'http://dev.includes.company.com' | set-content $target\Builds\$config\header.html 
} 

If ($config -eq "QA") 
{ 
    (get-content $target\common\css\stylesheet.min.css) -replace '{SERVER}', 'http://qa.includes.company.com' | set-content $target\Builds\$config\common\css\stylesheet.min.css 
    (get-content $target\header.html) -replace '{SERVER}', 'http://qa.includes.company.com' | set-content $target\Builds\$config\header.html 
} 

If ($config -eq "Release") 
{ 
    (get-content $target\common\css\stylesheet.min.css) -replace '{SERVER}', 'http://includes.company.com' | set-content $target\Builds\$config\common\css\stylesheet.min.css 
    (get-content $target\header.html) -replace '{SERVER}', 'http://includes.company.com' | set-content $target\Builds\$config\header.html 
} 

これは、デバッグ、およびリリースのための素晴らしい作品ではなく、のように見えるので...

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file "$(MSBuildProjectDirectory)\pbuild.ps1" "$(Configuration)" $(MSBuildProjectDirectory) 

のように見えるビルド後のイベントを持っていますQA。私が知るようになったところで、変数$ Configurationは、私が探している実際のActive Configurationではなく、「Debug」または「Release」を含むように見えます。

FlavorToBuildは有望そうに思えましたが、私は時間をかけて、私が使用できる変数に引き出しています。

私が探しているもの、アクティブなビルド構成の名前を与えるための変数がありますか?ビルド後のイベントにフィードできるプロジェクトファイルに変数を割り当てる方法はありますか?これはこの世界への私の最初の本当の進出です。そのため、どのようにこの目標を達成するための助けや指導が高く評価されます。

+0

"$(構成)"の代わりに "$(構成名)"にしないでください。 –

+0

1. [AfterBuild](http://msdn.microsoft.com/en-us/library/ms366724.aspx)targetあなたのスクリプトは[DRY](http://en.wikipedia.org/wiki/Don't_repeat_yourself)のルールに違反しています – KMoraz

+0

$(設定)と$(設定名)の両方が同じように見えるもの。 – Khepri

答えて

0

ビルドごとに1つまたは2つのプロパティをプロジェクトファイルに追加することで、これを解決したようです。

私は、次のようなものになってしまった:私は私として$ ReplaceWithと$ PowershellBuildEnvの両方を定義したプロジェクトファイルで

param ([string]$config, [string]$target, [string]$replaceWith) 

(get-content $target\common\css\stylesheet.min.css) -replace '{SERVER}', $replaceWith | set-content $target\Builds\$config\common\css\stylesheet.min.css 
(get-content $target\header.html) -replace '{SERVER}', $replaceWith | set-content $target\Builds\$config\header.html 

:今まで剥奪pbuild.ps1で

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file "$(MSBuildProjectDirectory)\pbuild.ps1" $(PowershellBuildEnv) $(MSBuildProjectDirectory) $(TargetSite) 

各ビルド構成のためのフィットを見た:だから

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> 
    <PowershellBuildEnv>Debug</PowershellBuildEnv> 
    <TargetSite>http://dev.includes.company.com</TargetSite> 

、私はトイレだと同じように動作するようです王はこの時点で間違いなく学習経験を積んだ。