TFS build server running Unit tests with different configuration - mstest

I am using TFS 2013 as a build server. And I have a test project that is using the unit test framework of visual studio 2013.
I am writing unit tests that is checking rest services.
I want to run these tests for the three environments: dev/test/prod
so, I am going to have three build definitions , one for each environment.
But my question is on how to configure the config files.
Is it possible to have three config file (app.config), which will be picked by the build project?
what is the easiest way to do that?

In the build definition you can specify which solution configuration to be build (dev/test/prod) and you can use SlowCheetah - XML Transforms to create your different config files in the project.

Related

Clarification on correct usage of TFS to publish Web Application

I'm trying to setup CI via TFS 2015, I've got a solution that has got 2 main Web application that currently we deploy manually editing the config files and so on (which sometimes leads to errors)
I've read about build/release process and in the past I've used Jenkins as build server. But till today I've got a question and that's related to when apply the transformation of XML config files.
In my current VTFS2015 setup I've created a build process and I build the project with the following line
msbuild /p:Configuration=Test /p:PublishProfile=Test /p:DeployOnBuild=true xxx\xxx.csproj
This creates me in the folder obj\Test\Package\PackageTmp the package
Is this ok? or should this be done in the release management tab? Consider in my farm I've
Test (from DEV trunk)
Staging (from Dev trunk as well)
Production (from production trunk on 3 machines)
My goal is to have them automatically delivered on the machines, but I don't know the right moment to apply the transformation (during the build I can use the publish feature, during the RM I can use a ps1 script)
Thanks in advance
Well, I think this thread will helps: What TFS 2017 build task applies web.config transforms during TFS builds?
To apply the transformations you can use the extension: Apply transformations in vNext build process.
Usually it should be a package and be used in a deploy task such as
Deploy: WinRM - IIS Web App Deployment or Azure App Service
Deployment to achieved the deployment.
1) Can transforms be engaged in both Builds and Releases?
Yes, you could also do this in a build pipeline with the useage of build deploy task. You need to add the task after the publish build
artifacts task.
2) Does TFS 2017 require a lot of special handling to engage a
transform file?
update
The BuildConfiguration variable is different in TFS 2017, it's inside
the MSBuild task! Transforms are now applied according
to the MSBuild task Configuration setting.
Edit the .proj file is a method to do the transform. If you don't need to change the transform, it will auto do it during the build.You
could also use some 3-rd party task/extension for extra transform such
as: XDT Transform
Usually we separate the build and release for the deployment, cause
it's easy to configure multiple environments and easy to debug issue.
You definitely could do this only in build but with a bloated process.
You could refer this tutorial: Build and Deploy Azure Web Apps using
Team Foundation Server/Services vNext Builds.
For a separate build and release solution, you could take a look at
this blog: Using web.config transforms and Release Manager – TFS
2017/Team Services edition

WebDeployment is not

I am trying to deploy an web application that was created on VB with the .NET Framework 2.0 using the TFS 2017 continuous deploy. It doesn’t have a solution file inside like vbproj or csproj, so I needed to avoid all the suggestions to include extra information on the vbproj.In order to run the MSBuild even locally I need to change in my .sln this tag, so all my compiled code is also there
Debug.AspNetCompiler.TargetPath = "....\PrecompiledWeb\ARB\Debug\"
Unfortunately, I can’t deploy the application using the TFS. So far I tried to deploy it through my Visual Studio project, and is working fine with every option: I tried MSDeploy, Web Deploy Package, and FileSystem, and is working fine from the Visual Studio Publish Option
With that, even my transformation take place.
Now lets say I go to my TFS and I put this parameters on the MSBuild
/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsASingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="\\MyServer\Content"
My files are compiled but never stored in my Content folder. No one of them!!! I can’t figure out what is going on here.
From your screenshot, you are using a Web Site project, not a Web Application project. The output structure of a Web Site project in TFS is different from build in VS (you can see a PrecompiledWeb folder in your build source directory on build agent server). Instead of using MSBuild argument, you can consider add tasks below to copy the files you want to publish:
We strongly suggest you switch from Web Site projects to Web Application projects to avoid these issues.

Create a web deploy package outside visual studio source code

I'm trying to create web deploy packages through visual studio team services.
Currently, I have created a web deploy publish profile in Visual Studio. I use MSBuild in Visual Studio Team Services to build the solution and create a web deploy package. I then zip the package and save it to a shared location. However, the issue with this approach is that it does not provide me a way have a same build for different environments. Let us say, I created a web deploy package for DEV environment. Then when I have to deploy the build to SIT environment, I would need to build the solution again and create a package. This way I would have different builds for different environments. I would like to have the same build get promoted to different environment for better traceability and maintenance.
One way I feel I can achieve this is to have a separate build definition for just building the application and save the DLLs to a shared location. I can then have a separate build definition which takes the build from shared location and create a web deploy package from the build. How can I achieve that on VSTS?
Other way possible is creating a label when any deployment happens one environment, say Dev environment. To do the deployment in SIT I can use the source code with same label and then use MSBuild to create a web deployment package. Is there any way to achieve this through VSTS with/ without creating a separate build definition of each environment?
Any other suggestions than above?
You can use VSTS Release Management to deploy your deployment package to different environment and use "Tokenizer" task in Release Management Utility tasks to update the config file in the package base on the variable for different environment configurations.
And you can also try with Web Deploy Parameterization.

TFS 2012 deploying mutliple profiles after build

I am currently using a build definition for continuous integration in TFS 2012.
I am using the following build arguments
/p:DeployOnBuild=true;PublishProfile=DEV_SERVER;Password=secret
and everything works well.
Now I need to publish the build to more than one site, and I have created the publishing profiles in visual studio. But how to tell MSBuild to use more than one profile?
/p:DeployOnBuild=true;PublishProfile=DEV_SERVER1;Password=secret /p:DeployOnBuild=true;PublishProfile=DEV_SERVER2;Password=secret /p:DeployOnBuild=true;PublishProfile=DEV_SERVER3;Password=secret
does not work. Only one site is published. (I'm not sure the first or last)
Does anyone know how to specify?
I know that I can duplicate the build definition on TFS using another profile in this new build definition, but in this case the application will be built TWO times and the releases on the servers have different build numbers.
you can specify publish xml in the MSBuild arguments
/t:Build /t:Publish /p:SqlPublishProfilePath=DEV.publish.xml
also this option only works for TFS2012 and VS2012

Unit test framework using deployment directories when deployment is disabled - how to clear?

Environment: Visual Studio 2010 Premium
Using the MS Unit Test Framework I have many projects in a solution that run fine, either with or without deployment enabled in the testsettings file. One project, when run with deployment DISABLED insists on looking for files in the deployment directory and consequently fails since the context is without deployment. I cannot find where or how VS has decided for this 1 project (out of many) it should be using a deployment directory (i.e. TestResults/......
Can any one suggest how to get VS to make this project behave just like all others in the solution. Also, no class attributes for deployment items are in use for this set of test classes.

Resources