【问题标题】:MSDeploy runCommand using relative pathMSDeploy runCommand 使用相对路径
【发布时间】:2011-06-19 13:26:14
【问题描述】:

我正在尝试通过 MSDeploy 在我的打包/部署过程中运行一个命令。特别是,我试图通过对我的一个 DLL 运行 installutil 来创建自定义事件日志,但是我无法从部署目录。首先,我将以下配置添加到我的 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。然后我可以写类似:&lt;path&gt;installutil $DeploymentDir\NewTestApp\bin\BusinessLayer.dll&lt;/path&gt;,而不必担心硬编码绝对路径。

有什么方法可以在不每次都使用我的 DLL 的绝对路径的情况下做到这一点?

【问题讨论】:

    标签: deployment msbuild msdeploy web-deployment webdeploy


    【解决方案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
    

    “站点名称”作为参数传递到 powershell 脚本中。在脚本内部,它知道该目标服务器上要安装哪些文件、需要运行的任何命令、要回收的应用程序池等。

    同样,虽然没有找到相对路径那么容易,但它确实可以完成这项工作。

    【讨论】:

    【解决方案2】:

    您可以使用上面编写的操作将 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>
    

    【讨论】:

    • 这只适用于在构建时指定的 DeploymentDir。但是一旦部署包要部署到生产网站,谁知道目标机器上的物理部署目录是什么。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-10
    • 2014-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-14
    相关资源
    最近更新 更多