使用相对路径的MSDeploy runCommand

15

我正试图通过MSDeploy将一个命令作为我的打包/部署过程的一部分运行。具体来说,我正在尝试运行installutil来对我的DLL之一创建自定义事件日志,但是我在指定从部署目录到DLL的相对路径时遇到了问题。为了开始操作,我在我的csproj中添加了以下配置以生成运行命令提供程序并放入我的清单文件中。请注意DLL的绝对路径。

<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 

我遇到的问题是我不想硬编码c:\inetpub\etc的DLL路径。我如何使用从Default Web Site下的部署目录相对路径进行上述调用?理想情况下,我希望MSDeploy获取此路径并将其作为变量传递给runCommand语句,以便找到DLL。然后我可以写像这样的内容:<path>$DeploymentDir\NewTestApp\bin\BusinessLayer.dll</path>,而无需担心硬编码绝对路径。

是否有任何方法可以在每次使用DLL时不使用绝对路径?

2个回答

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>

这些条件将允许您从命令行更改所有内容,以便在构建系统或脚本中完全控制构建过程。
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”。但是,一旦部署包将要部署到生产网站上,谁知道目标机器上的物理部署目录会是什么。 - Steve Michelotti

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

“sitename”被作为参数传递到PowerShell脚本中。在脚本内部,它知道在目标服务器上安装哪些文件、需要运行哪些命令、要回收哪些应用程序池等。

虽然不像查找相对路径那么简单,但它确实能够完成工作。


1
这似乎也是一个相当官方的建议:http://social.msdn.microsoft.com/Forums/en/msbuild/thread/1044058c-f762-456b-8a68-b0863027ce47 - Merlyn Morgan-Graham

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接