How to have different Teamcity VSBuild Configurations (Debug/Release) for each specific branch? - msbuild

I have a build configuration that does my building and unit testing for all of my branches of my project. I have another configuration that does my deploying. I need the first configuration to do the build with a "Debug" target if its against a "development" environment and a "Release" target against the rest. Is there a way to go about this without having to make different build configurations?

For all the builds I manage here at my job, we always create different build configurations in TeamCity for Debug and Release. I don't know more about your build environment so obviously I can't answer specifically.
You can however reduce almost all the duplication by using templates. Which is nice. Then the only unique information in your debug build is the word 'Debug', and same for your 'Release' build.

Related

MsBuild: Forcing a rebuild when changing build configuration

I have a #if in a project that depends on which build configuration is selected (eg: Debug, QA, and other test environments). When a user changes the build configuration in VS2015/Xamarin Studio, I need the IDE to force a rebuild on this project when the user builds the solution. How do I do this? At the moment, rebuilding the solution will reuse the compiled dll's.
In other words, how do I set a project dirty after a user changes the build configuration to force a rebuild.
Make sure the Output path of the project is unique to the build configuration. Otherwise MsBuild will just compare the timestamp of the input files and the existing output files and will conclude that a rebuild is not required.
It is assumed that when two projects build a different configuration, that they also write to a different folder for this reason.
Normally the output location is set to .\bin\$(configuration) to ensure this is the default behavior.

How do I disable Teamcity deploying artifacts for personal builds?

I am using Teamcity 9.0.2 and IntelliJ 14.1.5. I have a Teamcity build with a maven step configured with "Deploy Maven artifacts" enabled.
When I run a personal build, the artifacts get deployed to artifactory.
How do I disable deploying artifacts for personal builds by default for each of my builds?
Currently it's not possible to execute build steps based on condition. Vote for the related request: https://youtrack.jetbrains.com/issue/TW-17939.
As of now you can:
Create a separate build configuration without Deploy build step (recommended). You can use templates to simplify the setup. In this case it will be easier to interpret the results and the statistics of the builds will be informative.
If build is personal %system.build.is.personal% parameter is set to true. So you can check a condition in the build step and skip it if needed.
This is the workaround i found to this issue. I created two additional build steps, The first labeled "Check for Personal Build" is a Nant step that validation against the BUILD_IS_PERSONAL environmental variable, and if set, updates a teamcity env.PublishPath variable.
<project name="UpdateForPersonal" default="default">
<target name="default">
<if test="${environment::variable-exists('BUILD_IS_PERSONAL')}">
<echo message="##teamcity[setParameter name='env.PublishPath' value='fake']" />
</if>
</target>
</project>
The second step is a simple CMD the writes as dummy "Publish" message to the logs, but the "Custom published artifacts" values is from the "Deploy Artifacts To Artifactory" section padded by %env.PublishPath%.
If the build is personal, the publish to artifactory will not find any files and log warnings into the logs, but the build passes and no artifacts are published.
The value of %env.PublishPath% is set to "" by default in the configuration build.

MSBuild - Run tests only on Release build

Our MSBuild definitions build both Debug and Release build configurations. (This is due to the deployment system we use and can't be changed.) The problem is that since we run automated tests, they are run twice, once on each build. Is there any way for me to configure tests to be run only on release build?
We're using VS2010/TFS2010.
In the TFS build definition, under the Process tab, under Automated Tests -> Test Sources -> Test Sources Spec, can you modify the path spec to include the name of the releases folder so that the test binaries from the releases folder only are tested?
Change the spec from:
**\MyApp*Tests.dll
To read:
**\Release\**\MyApp*Tests.dll
It looks like a little tweak to Nick's answer did the trick.
..\Release\**\MyApp*Tests.dll

Build in TFS with multiple project is not taking the correct transformation web config

I have a solution in VS2010 and it has three project, two of these projects have web config file, the projects have web config transformation for each environment (dev, test and prod).
At the process for TFS build option, I have the at the MSBuild Arguments : /p:DeployOnBuild=True
Everything looks good, the drop folder, the zip files and all structure for the final deployment. The issue I am facing the web config for test and prod is not created correctly after the final deployment, I could see at the drop folders the file projectName.SetParameters.xml, it contains the values for development when the build has been QUEUE for Test and Prod. One of the project has the correct web config (test and prod) but the other project has always the dev webconfig.
Is it a bug in the MS Build? What am I missing in the build parameters?
When I create a build deployment package the web config transformation creates the correct web config file, no issues with this process, but I do not want to use build deployment package to deploy my solution.
Any help will be appreciated.
Thank you.
In your Build Definition you probably defined the Configurations to use. Part of that also defines something like Any CPU or x86. As it turns out the solution the Platform "Any CPU" has a space where in the project files the Platform Any CPU does not have a space.
I found the best way to get around this was to leave the Platform blank and only put in the configuration name. VS will pop up a warning letting you know that there is data missing, you can just hit "Yes" to save it anyways. Alternatively you can just type in your configurations like the following |Release,|Debug.
The pattern is [PlatformName]|[ConfigurationName],[PlatformName]|[ConfigurationName],...

Running rsvars.bat before Teamcity build starts

I have a C++ Builder 2010 project that's being built using TeamCity. I noticed some strange errors and after reading up on them I understand that I have to set a few variables located in rsvars.bat. I would like the build script to execute the bat file to set up the environment before performing the actual build. How do I best accomplish this?
Can I just use a <exec /> command at the very beginning of the file or is there a better way?
One way would be to run wrap the build in a script that calls rsvars.bat AND build commands. That would make the variables survive during the execution of the build.
But since I use TeamCity I like it to be a real msbuild step and not msbuild wrapped in something else. I was thinking of having the buildscript setting the variables from rsvars.bat into Machine or User at the start of the build and then remove them at the end, not nice though.
I finally just went with just adding the configurations to the Build Agents environment configuration in TeamCity and keeping installation paths identical between agents.
You can create a new build step and then specify a custom build step order so a new build step will be the first one.
See Configuring Build Steps
Add them as Build Parameters -> Environment Variables (in the build configuration), straight forward and generally works. The build parameter/environment variables will be setup automatically as environment variables on the build agent running the job.
You can then make a template of the build and reuse it.
Assumes that the 'paths' are the same on all build agents, which is generally the case. If not your suggestion of doing it by build agent is the way to go.