简体   繁体   English

Web Deploy (MSDeploy) 3.6 替换规则重命名文件

[英]Web Deploy (MSDeploy) 3.6 replace rule to rename a file

I'm using msdeploy on the command-line to deploy a windows service using the sync verb against dirPath source and destination providers.我在命令行上使用 msdeploy 使用针对dirPath源和目标提供程序的sync动词来部署 Windows 服务。 So far so good.到现在为止还挺好。

My project's build assets have per-environment config files, and during deploy to a particular environment I want to rename the targeted environment's config file to the default config file name using a replace rule, but no matter how I engineer my replace rule nothing seems to get me the results I want.我的项目的构建资产具有每个环境的配置文件,在部署到特定环境期间,我想使用替换规则将目标环境的配置文件重命名为默认配置文件名,但无论我如何设计替换规则,似乎都没有让我得到我想要的结果。 I've tried with a number of different configurations of the rule with no luck but the one that seems the most logical is this one:我尝试了许多不同的规则配置,但没有运气,但似乎最合乎逻辑的是这个:

-replace:objectName=filePath,scopeAttributeName=path,scopeAttributeValue=Service\.Dev\.exe\.config,match=Service\.Dev\.exe\.config,replace=Service.exe.config

If I deploy without the replace rule both Service.Dev.exe.config and Service.exe.config are deployed with the expected respective content.如果我在没有替换规则的情况下部署Service.Dev.exe.configService.exe.config都部署了预期的相应内容。 Once I add the replace rule above I get just Service.exe.config and it's got the content of that file from the source, not the content of Service.Dev.exe.config as I am hoping for.一旦我添加了上面的替换规则,我就得到了Service.exe.config并且它从源中获得了该文件的内容,而不是我希望的Service.Dev.exe.config的内容。 If I swap the specifications of the match and replace components (and change regexp <-> plain text accordingly) to arrive at:如果我交换match的规范并replace组件(并相应地更改正则表达式 <-> 纯文本)以达到:

-replace:objectName=filePath,scopeAttributeName=path,scopeAttributeValue=Service\.Dev\.exe\.config,match=Service\.exe\.config,replace=Service.Dev.exe.config

I just get Service.Dev.exe.config with the content of Service.exe.config and no Service.exe.config in the destination.我只是获得了Service.Dev.exe.config的内容,其中包含Service.exe.config的内容,而目标中没有Service.exe.config

I'm sure I'm missing something obvious, but what is it?我确定我遗漏了一些明显的东西,但它是什么?

This doesn't directly answer your question but I think its a better solution to your root problem.这并不能直接回答您的问题,但我认为它是解决您的根本问题的更好方法。

The real issue here is config management for different environments.这里真正的问题是不同环境的配置管理。 Many developers create different configs for each environment like you do.许多开发人员像您一样为每个环境创建不同的配置。 This approach requires a lot of duplication across your different config files which can easily get out of sync.这种方法需要在不同的配置文件中进行大量重复,这很容易不同步。

The best approach I've found for managing configuration across different environments is WebDeploy Parameterization.我发现的跨不同环境管理配置的最佳方法是 WebDeploy 参数化。 It is similar to config transforms in that you have a single base config file that is tweaked, so there is far less duplication.它类似于配置转换,因为您有一个经过调整的基本配置文件,因此重复少得多。 Parameterization however is preferred because it applies the changes at deploy time instead of build time.然而,参数化是首选,因为它在部署时而不是构建时应用更改。 We use this for 50+ applications with great success.我们将此用于 50 多个应用程序并取得了巨大成功。

Here is a blog post with more details - http://www.dotnetcatch.com/2014/09/08/parameterizationpreview-visual-studio-extension/这是一篇包含更多详细信息的博客文章 - http://www.dotnetcatch.com/2014/09/08/parameterizationpreview-visual-studio-extension/

匹配和替换应该交换

match=Service.Dev.exe.config,replace=Service\\.exe\\.config

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM