MSDeploy runCommand使用相对路径

时间:2011-02-01 20:44:40

标签: deployment msbuild msdeploy web-deployment webdeploy

我正在尝试通过MSDeploy运行命令作为我的打包/部署过程的一部分。特别是,我试图通过对我的一个DLL运行 installutil 来创建一个自定义事件日志,但我在从DLL指定一个相对路径时遇到问题部署目录。首先,我将以下配置添加到我的csproj中,以便在我的Manifest文件中生成runCommand提供程序。请注意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 

我遇到的问题是我不想将此DLL路径硬编码到c:\ inetpub \ etc。如何使用默认网站下的部署目录中的相对路径进行上述调用?理想情况下,我希望 MSDeploy 采用此路径并将其作为变量传递给runCommand语句,以便找到DLL。然后我可以编写类似:<path>installutil $DeploymentDir\NewTestApp\bin\BusinessLayer.dll</path>的内容,而不必担心硬编码绝对路径。

有没有办法在不使用我的DLL的绝对路径的情况下每次都这样做?

2 个答案:

答案 0 :(得分:4)

您可以使用上面描述的操作将.DepddD的定义添加到.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>

答案 1 :(得分: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脚本中。在脚本内部,它知道该目标服务器要安装哪些文件,需要运行的任何命令,要回收的应用程序池等等。

同样,不像找到相对路径那么容易,但是它完成了工作。