我目前正在开展一个重新平台项目,其中一部分涉及几十个网站,所有这些都使用了一个共同的标题。其中一些网站都存在于同一台机器上,因此设置了符号链接,因此它们都可以引用相同的内容。某些其他网站是外部网站,因此设置并使用了常见的“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
}
这适用于Debug和Release,但不适用于QA。正如我已经发现的那样,变量$ Configuration似乎只包含'Debug'或'Release',而不是我正在寻找的实际Active Configuration。
FlavorToBuild看起来很有希望,但是我有一段时间可以把它变成一个我可以使用的变量。
是否设置了一个变量来提供我正在寻找的内容,即活动构建配置的名称?有没有办法在项目文件中分配一个变量,然后我可以将其输入到Post-Build事件中?这是我第一次真正涉足这个世界,所以对如何实现这一目标的任何帮助或指导都非常感谢。
答案 0 :(得分:0)
我似乎通过在每个构建的项目文件中添加一个或两个属性来解决这个问题。
我最终得到了以下内容:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file "$(MSBuildProjectDirectory)\pbuild.ps1" $(PowershellBuildEnv) $(MSBuildProjectDirectory) $(TargetSite)
pbuild.ps1的现在被剥离为:
param ([string]$config, [string]$target, [string]$replaceWith)
(get-content $target\common\css\stylesheet.min.css) -replace '{SERVER}', $replaceWith | set-content $target\Builds\$config\common\css\stylesheet.min.css
(get-content $target\header.html) -replace '{SERVER}', $replaceWith | set-content $target\Builds\$config\header.html
在项目文件中,我定义了$ ReplaceWith和$ PowershellBuildEnv,因为我认为适合每个构建配置:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PowershellBuildEnv>Debug</PowershellBuildEnv>
<TargetSite>http://dev.includes.company.com</TargetSite>
所以,似乎就像我正在寻找的那样。绝对是一次学习经历。