使用相对路径的 MSDeploy runCommand

发布于 2024-10-15 08:19:37 字数 1738 浏览 8 评论 0原文

我正在尝试通过 MSDeploy 运行命令作为打包/部署过程的一部分。特别是,我尝试通过针对我的一个 DLL 运行 installutil 来创建自定义事件日志,但在从 DLL 指定相对路径时遇到了问题。部署目录。首先,我将以下配置添加到我的 csproj 中,以便在清单文件中生成 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。然后我可以编写如下内容: installutil $DeploymentDir\NewTestApp\bin\BusinessLayer.dll 而不必担心硬编码绝对路径。

有什么办法不每次都使用 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>

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 

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

窝囊感情。 2024-10-22 08:19:37

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

You can add definition of DeploymentDir to the .csproj with the action you wrote above:

<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 conditions will allow to change everything from command line to take full control over the build process in your build system or script.

MSBuild.exe yourproj.proj /p:Configuration=Release /p:DeploymentDir=D:\package /p:ApplivationName=BestAppForever

And inside of your task you can use it

<ItemGroup>
  <MsDeploySourceManifest Include="runCommand">
    <path>installutil $(ApplicationDeploymentDir)\BusinessLayer.dll</path>
  </MsDeploySourceManifest>
</ItemGroup>
听不够的曲调 2024-10-22 08:19:37

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

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

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

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

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

installutil C:\inetpub\wwwroot\MyTestApp\bin\BusinessLayer.dll ... etc

We would run:

c:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe d:\powershell\installSites.ps1 siteName <NUL

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文