使用相对路径的 MSDeploy runCommand
我正在尝试通过 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。然后我可以编写如下内容:
而不必担心硬编码绝对路径。
有什么办法不每次都使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用上面编写的操作将 DeploymentDir 的定义添加到 .csproj 中:
这些条件将允许从命令行更改所有内容,以完全控制构建系统或脚本中的构建过程。
在你的任务中你可以使用它
You can add definition of DeploymentDir to the .csproj with the action you wrote above:
Theese conditions will allow to change everything from command line to take full control over the build process in your build system or script.
And inside of your task you can use it
我意识到这可能不是您想听到的答案,但这就是我解决这个问题的方法。
我们在目标服务器上创建了一个 powershell 脚本。因此,我们不是运行命令:
而是运行:
“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:
We would run:
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.