Rebranding via PowerShell

I was working on a project recently where I wanted to update some variables in the source code at build time. On top of that, I wanted these variables to be hard coded into the output of the application and not modifiable via a configuration file. A great use case would be rebranding (or white labeling) a piece of software to sell to multiple different customers while making it more difficult for the customer to do the same. After researching a few solutions, I went with a customer PowerShell script as a build step in Visual Studio Team Services (VSTS) that runs before the build step.

To start we need to create a console application:

Next we need to add the PowerShell Script:

To customize this to your specific code needs, update the private static string CustomName to an appropriate variable name.

After the program and script are pushed to source control, the next step is to create a new build definition in VSTS. I created my build definition based on the .NET Desktop Build Template:

Once the template is created we need to add the PowerShell build step:

Once the PowerShell build step is added it should be placed immediately before the build solution step:

Next we add the parameters for the PowerShell build step:

Specifically we need to add the path to the PowerShell file that is checked into source code in the Script Path parameter. And add the arguments. By using -customname “$(CustomName)” it’s specifies this should be a VSTS variable that we’ll configure to be set at build time.

Next we need to add the CustomName VSTS variable:

(The variable name needs to match the name we specified in the PowerShell arguments $(CustomName) and Settable at queue time should be checked.)

Finally we need to save and queue a build:

(This is where we specify the custom name)

Once the build completes (109 seconds on host VSTS 2017 Agent for me) you can access the output files for the artifacts tab and download them:

To see the result of the rebranding open the zip file and navigate to the console application and run it:

This is a simplified process for rebranding, but hopefully you can build upon this to suit your needs. If you have any question or comments please let me know: [email protected].


Leave a Comment

Your email address will not be published. Required fields are marked *