Visual Studio 2010 Post-Build Event: Passing Current FlavorToBuild

I am currently working on a redesign project, part of which includes several dozen websites, all of which share a common title. Some of these sites all lived on the same machine, so a symbolic link was set up so they could link to the same content. Several other sites were external and therefore the generic "includes.company.com" was installed and used.

Fast forward and I am trying to set up the "includes.company.com" site in Visual Studio. The content is pretty simple. I have combined it into one HTML file and one CSS file along with all the required images.

What I am trying to accomplish now is based on the current build configuration to output HTML and CSS with appropriate links that can be referenced from external sites.

I currently have a post-build event that looks like this ...

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file "$(MSBuildProjectDirectory)\pbuild.ps1" "$(Configuration)" $(MSBuildProjectDirectory)

      

where pbuild.ps1 looks like

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
}

      

This works great for Debug and Release, but not for QA. As I have already figured out, the $ Configuration variable seems to ever contain "Debug" or "Release" rather than the actual active configuration I am looking for.

FlavorToBuild seemed promising, but I'm getting a heck of a time it pulls into a variable that I can use.

Is there a variable that is configured to give me what I'm looking for, the name of the active build configuration? Is there a way to assign a variable in the project file that I can pass to my Post-Build event? This is my first real foray into this world, so any help or guidance in achieving this goal is greatly appreciated.

+3


source to share


1 answer


I seem to have solved this by adding a property or two to the project file for each build.

I ended up with something like the following:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file "$(MSBuildProjectDirectory)\pbuild.ps1" $(PowershellBuildEnv) $(MSBuildProjectDirectory) $(TargetSite)

      

with pbuild.ps1 now split to:



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

      

In the project file I have defined both $ ReplaceWith and $ PowershellBuildEnv as I see fit for each build configuration:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PowershellBuildEnv>Debug</PowershellBuildEnv>
    <TargetSite>http://dev.includes.company.com</TargetSite>

      

So, it looks like I work the same way as I do now. Definitely a learning experience.

0


source







All Articles