【发布时间】:2012-03-27 01:22:44
【问题描述】:
我目前正在开展一个重新平台化项目,其中一部分涉及几十个网站,所有这些网站都使用一个共同的标头。其中几个站点都位于同一台机器上,因此设置了符号链接,以便它们都可以引用相同的内容。某些其他网站是外部网站,因此设置和使用了一个常见的“includes.company.com”。
快进到今天,我正在尝试在 Visual Studio 中设置“includes.company.com”站点。内容很简单。我将其归结为一个 HTML 文件和一个 CSS 文件以及所有必要的图像。
我现在想要完成的是基于当前的构建配置,输出带有可以从外部站点引用的正确链接的 HTML 和 CSS。
我目前有一个看起来像这样的构建后事件......
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file "$(MSBuildProjectDirectory)\pbuild.ps1" "$(Configuration)" $(MSBuildProjectDirectory)
pbuild.ps1 的样子
param ([string]$config, [string]$target)
If ($config -eq "Debug")
{
(get-content $target\common\css\stylesheet.min.css) -replace '{SERVER}', 'http://dev.includes.company.com' | set-content $target\Builds\$config\common\css\stylesheet.min.css
(get-content $target\header.html) -replace '{SERVER}', 'http://dev.includes.company.com' | set-content $target\Builds\$config\header.html
}
If ($config -eq "QA")
{
(get-content $target\common\css\stylesheet.min.css) -replace '{SERVER}', 'http://qa.includes.company.com' | set-content $target\Builds\$config\common\css\stylesheet.min.css
(get-content $target\header.html) -replace '{SERVER}', 'http://qa.includes.company.com' | set-content $target\Builds\$config\header.html
}
If ($config -eq "Release")
{
(get-content $target\common\css\stylesheet.min.css) -replace '{SERVER}', 'http://includes.company.com' | set-content $target\Builds\$config\common\css\stylesheet.min.css
(get-content $target\header.html) -replace '{SERVER}', 'http://includes.company.com' | set-content $target\Builds\$config\header.html
}
这适用于调试和发布,但不适用于 QA。我发现,变量 $Configuration 似乎只包含“调试”或“发布”,而不是我正在寻找的实际活动配置。
FlavorToBuild 看起来很有希望,但我很难将其提取到我可以使用的变量中。
是否设置了一个变量来提供我正在寻找的内容,即活动构建配置的名称?有没有办法在项目文件中分配一个变量,然后我可以将其输入到我的 Post-Build 事件中?这是我第一次真正涉足这个世界,因此非常感谢任何有关如何实现这一目标的帮助或指导。
【问题讨论】:
-
不应该是"$(ConfigurationName)" 而不是"$(Configuration)。
-
1. AfterBuild 目标比构建后事件要好得多。 2.你的脚本违反了DRY规则
-
$(Configuration) 和 $(ConfigurationName) 似乎给出了相同的东西。
标签: visual-studio powershell msbuild post-build-event