MSDeploy runCommand使用相对路径

MSDeploy runCommand使用相对路径

问题描述:

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

I am trying to run a command as a part of my packaging/deployment process via MSDeploy. In particular, I am trying to create a custom event log by running installutil against one of my DLLs, but I am having trouble with specifying a relative path to the DLL from the deployment directory. To get started, I added the below config to my csproj in order to generate the runCommand provider inside of my Manifest file. Please note the absolute path to the 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并从下面的清单运行我的命令:

After calling msbuild, this generated my manifest correctly inside of my package.zip. When I ran MyTestApp.deploy.cmd /Y it correctly called msdeploy and deployed my files to inetpub\wwwroot\MyTestApp and ran my command from the manifest below:

<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> 而不必担心硬编码绝对路径。

The problem I am having is I do not want to hardcode this DLL path to c:\inetpub\etc. How can I make the above call using the relative path from my deployment directory under Default Web Site? Ideally, I would like MSDeploy to take this path and pass it as a variable to the runCommand statement in order to find the DLL. Then I could write something like: <path>installutil $DeploymentDir\NewTestApp\bin\BusinessLayer.dll</path> without having to worry about hard-coding an absolute path in.

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

Is there any way to do this without using the absolute path to my DLL every time?

我意识到这不是你可能想听到的答案,我遇到了

I realize this isn't the answer you probably wanted to hear but this is how I got around it.

我们在目标服务器上创建了一个powershell脚本。所以,而不是运行你的命令:

We created a powershell script on the destination server. So instead of running your command:

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脚本。在脚本中,它知道目标服务器上要安装哪些文件,需要运行的任何命令,应用程序池进行回收等。

The "sitename" is being passed in as a param into the powershell script. Inside the script it knows on that destination server which files to install, any commands that need to run, app pools to recycle, etc.

再次,找不到一个相对的路径,但它做的工作。

Again, not as easy as finding a relative path, but it does the job.