MSDeploy runCommand使用相对路径

skM*_*Med 15 deployment msbuild web-deployment msdeploy 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>
Run Code Online (Sandbox Code Playgroud)

在调用msbuild之后,这在package.zip中正确生成了我的清单.当我运行MyTestApp.deploy.cmd/Y时,它正确调用了msdeploy并将我的文件部署到inetpub\wwwroot\MyTestApp并从下面的清单中运行我的命令:

<runCommand path="installutil C:\inetpub\wwwroot\MyTestApp\bin\BusinessLayer.dll ... etc 
Run Code Online (Sandbox Code Playgroud)

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

有没有办法这样做,而不是每次都使用我的DLL的绝对路径?

Pau*_*mke 1

我意识到这可能不是您想听到的答案,但这就是我解决这个问题的方法。

我们在目标服务器上创建了一个 powershell 脚本。因此,不要运行命令:

installutil C:\inetpub\wwwroot\MyTestApp\bin\BusinessLayer.dll ... etc
Run Code Online (Sandbox Code Playgroud)

我们会运行:

c:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe d:\powershell\installSites.ps1 siteName <NUL
Run Code Online (Sandbox Code Playgroud)

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

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