2011-02-01 29 views
15

我試圖經由MSDeploy我的包裝/部署過程的一部分運行命令。特別是,我試圖通過運行installutil對我的DLL來創建自定義事件日誌,但我有指定從部署目錄下的DLL一個相對路徑麻煩。要開始,我將下面的配置添加到我的csproj中,以便在我的Manifest文件中生成runCommand提供程序。請注意DLL的絕對路徑。MSDeploy runCommand使用相對路徑

<PropertyGroup> 
    <!-- Extends the AfterAddIisSettingAndFileContentsToSourceManifest action to create Custom Event Log --> 
    <IncludeEventLogCreation>TRUE</IncludeEventLogCreation> 
    <AfterAddIisSettingAndFileContentsToSourceManifest Condition="'$(AfterAddIisSettingAndFileContentsToSourceManifest)'==''"> 
     $(AfterAddIisSettingAndFileContentsToSourceManifest); 
     CreateEventLog; 
    </AfterAddIisSettingAndFileContentsToSourceManifest> 
    </PropertyGroup> 
    <Target Name="CreateEventLog" Condition="'$(IncludeEventLogCreation)'=='TRUE'"> 
    <Message Text="Creating Event Log" /> 
    <ItemGroup> 
     <MsDeploySourceManifest Include="runCommand"> 
     <path>installutil C:\inetpub\wwwroot\MyTestApp\bin\BusinessLayer.dll</path> 
     </MsDeploySourceManifest> 
    </ItemGroup> 
    </Target> 
    <ItemGroup> 

調用msbuild後,這在我的package.zip中正確生成了我的清單。當我跑MyTestApp.deploy.cmd/Y它正確調用msdeploy和部署我的文件的Inetpub \ wwwroot文件\ MyTestApp並從下面的清單跑到我的命令:

<runCommand path="installutil C:\inetpub\wwwroot\MyTestApp\bin\BusinessLayer.dll ... etc 

我遇到的問題是我做的不想將此DLL路徑硬編碼到c:\ inetpub \ etc。如何在默認網站下的我的部署目錄中使用相對路徑進行上述呼叫?理想情況下,我想MSDeploy走這條路,並把它作爲一個變量來runCommand聲明,以便找到DLL。然後我可以寫如:<path>installutil $DeploymentDir\NewTestApp\bin\BusinessLayer.dll</path>,而不必擔心硬編碼絕對路徑英寸

有沒有辦法做到這一點,而不是每次都使用我的DLL的絕對路徑?

回答

1

我知道這不是你可能想聽到的答案,但這是我身邊如何到達。

我們在目標服務器上創建一個PowerShell腳本。因此,而不是運行你的命令:

installutil C:\inetpub\wwwroot\MyTestApp\bin\BusinessLayer.dll ... etc 

我們可以運行:

c:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe d:\powershell\installSites.ps1 siteName <NUL 

的「網站名稱」正在傳過來的PARAM到PowerShell腳本。它知道哪些文件來安裝目標服務器上的腳本中,需要執行的命令,應用程序池回收等

再次,還不如找一個相對路徑一樣簡單,但它的工作。

+1

這似乎是一個有點官方推薦,太:http://social.msdn.microsoft.com/Forums/en/msbuild/thread/1044058c-f762-456b-8a68-b0863027ce47 – 2011-10-04 02:57:08

4

您可以添加DeploymentDir的定義與你上面寫的動作的.csproj:

<PropertyGroup> 
<DeploymentDir Condition="'$(Configuration)'=='Release' AND '$(DeploymentDir)'==''">Release Deployment Dir</DeploymentDir> 
<DeploymentDir Condition="'$(Configuration)'=='Debug' AND '$(DeploymentDir)'==''">Debug Deployment Dir</DeploymentDir> 
<DeploymentDir Condition="'$(DeploymentDir)'==''">C:\inetpub\wwwroot</DeploymentDir> 
<AplicationName Condition="'$(Configuration)'=='Release' AND '$(AplicationName)'==''">NewTestApp</AplicationName> 
<AplicationName Condition="'$(Configuration)'=='Debug' AND '$(AplicationName)'==''">MyTestApp</AplicationName> 
<ApplicationDeploymentDir Condition="'$(ApplicationDeploymentDir)'==''">$(DeploymentDir)\$(ApplicationName)\bin</ApplicationDeploymentDir> 
</PropertyGroup> 

Theese條件允許改變一切的命令行全面接管在構建過程中構建系統或腳本。

MSBuild.exe yourproj.proj /p:Configuration=Release /p:DeploymentDir=D:\package /p:ApplivationName=BestAppForever 

而你的任務裏面,你可以用它

<ItemGroup> 
    <MsDeploySourceManifest Include="runCommand"> 
    <path>installutil $(ApplicationDeploymentDir)\BusinessLayer.dll</path> 
    </MsDeploySourceManifest> 
</ItemGroup> 
+4

這隻適用於在構建時指定的DeploymentDir。但是,一旦部署包將被部署到生產網站,誰知道物理部署目錄將在目標機器上。 – 2011-02-10 15:49:03