15

我正在尝试通过 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 的绝对路径?

4

2 回答 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>
于 2011-02-10T10:26:09.623 回答
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 脚本中。在脚本中,它知道该目标服务器上要安装哪些文件、需要运行的任何命令、要回收的应用程序池等。

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

于 2011-02-04T15:32:39.573 回答