VSTest - DeploymentItem defined in testsettings file is not being deployed to TestResults folder - vstest

I have a testsettings file with deployment items defined in it that deploys my files as I expect when I use it with MSTest. However, when I use the same testsettings file with vstest.console.exe the items do not get deployed to the TestResults folder. Do I need to do something differently to deploy specific files with vstest?
Here's the deployment section in the testsettings file:
<Deployment>
<DeploymentItem filename="C:\MyTests\testfile.txt" />
</Deployment>
Here's how I'm using it with MSTest that works:
MSTest.exe /testcontainer:"C:\Tests\MyTests.dll" /testsettings:"C:\Tests\ts.testsettings"
And here's how I'm using it with VSTest that is not working:
vstest.console.exe C:\Tests\MyTests.dll /Settings:"C:\Tests\ts.testsettings"

Please make sure DeploymentEnabled flag is true in runsettings file. By default this is true. Changing it to false doesn't copy Deployment Items to the out directory of the TestResults folder.
Example:
<MSTest>
<MapInconclusiveToFailed>True</MapInconclusiveToFailed>
<CaptureTraceOutput>false</CaptureTraceOutput>
<DeploymentEnabled>True</DeploymentEnabled>
</MSTest>
Reference https://msdn.microsoft.com/en-us/library/jj635153.aspx

Related

Publish on TFS does not find the pubxml file for Node.js test project

I created a Node.js project for an protractor test environment using the Node.js Tools to test a web application on a team foundation server. The test project and the web application are in one solution file. However, if i want to deploy the Node.js project on the tfs, it is not able to find the pubxml file located in the web application project.
Error log:
12>CoreCompile:
Creating directory "bin".
Copying file from "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Node.js Tools\Microsoft.NodejsTools.WebRole.dll" to "bin\Microsoft.NodejsTools.WebRole.dll".
ValidatePublishProfileSettings:
Validating PublishProfile(TestProfile) settings.
12>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets(4364,5): error : The value for PublishProfile is set to 'TestProfile', expected to find the file at '<PATH>\TestProject.Web.Protractor.Tests\__profiles\TestProfile.pubxml' but it could not be found. [<PATH>\TestProject.Web.Protractor.Tests.njsproj]
12>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets(4371,4): error : PublishProfile(TestProfile) is set. But the $(WebPublishMethod) does not have a valid value. Current Value is "". [<PATH>\TestProject.Web.Protractor.Tests.njsproj]
12>Done Building Project "<PATH>\TestProject.Web.Protractor.Tests.njsproj" (default targets) -- FAILED.
After analyzing the Microsoft.Web.Publishing.targets i found the PublishProfileRootFolder variable to change the search path for the pubxml file.
First i tried to place the variable inside the MSBuild arguments. However, this raised problems with other test projects and i was not able to use variables like the $(SolutionDir).
I ended trying to use the PublishProfileRootFolder variable inside the project file and this works now:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
...
<PublishProfileRootFolder>$(SolutionDir)PathToWebApplication\Properties\PublishProfiles</PublishProfileRootFolder>
</PropertyGroup>
...
PS: Additionally you need a Web.config file, placed in the project root of the test project:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<customErrors mode="on"/>
<compilation debug="true"/>
</system.web>
</configuration>

Sonar-Runner 2.4 can't find code coverage reports

I'm running SonarQube 5.2 with SonarRunner v2.4 (MSBuild) and am having issues getting SonarRunner to pick up the code coverage reports. I have VS Test which drops the TestResults folder within the source directory. The TRX file is within the TestResults folder. Is there a default directory that Sonar-Runner scans to search for the TRX/code coverage reports? The build succeeds but there are no unit test coverage results in SonarQube for the app.
TRX: F:\Builds\50\IT\ABCDemo.Nightly\src\TestResults\ *.TRX
Source:
F:\Builds\50\IT\ABCDemo.Nightly\src
Process:
SonarRunner begin //with key,name,version filled in
MSBuild executes
VS Test executes and drops TestResults folder within src directory.
SonarRunner end
Issue:
MSBuild SonarQube Runner Post-processor 1.0.2.0
09:22:57.327 Fetching code coverage report information from TFS...
09:23:17.723 No code coverage reports were found for the current build.
EDIT: I've included the .TRX and .coveragexml files using /d: but I still get the issue saying no code coverage reports were found.
I can see in the logs that it does:
09:51:59.875 INFO - Parsing the Visual Studio coverage XML report f:\Builds\50\IT\ABCDemo.Nightly\src\VisualStudio.coveragexml
09:53:07.737 INFO - Parsing the Visual Studio Test Results file f:\Builds\50\IT\ABCDemo.Nightly\src\TestResults\tfsbuildagent_QL1CIBUILD3 2015-12-03 09_51_33.trx
These occur near the end of sonar analysis.
Resolved by:
Included the paths to the files for trx and coveragexmls within the arguments for sonar-runner.
MSBuild.SonarQube.Runner.exe begin
/k:projectkey /n:projectname /v:projectversion
/d:sonar.cs.vstest.reportsPaths="path\to\ *.trx"
/d:sonar.cs.vscoveragexml.reportsPaths="path\to\VisualStudio.coveragexml"
Moved the /'s around for better visual.

Transform external config in a web role

Can slowcheetah transform an external config file in an azure web role? e.g. I have logging info in log4net.config. But the transformed version does not get created when packaged.
I did not manage to get slowCheetah working in my Azure solution.
One alternative you can use is to create complete config files for each environment - e.g. :
log4net.debug.config
log4net.release.config
and copy the contents of these into the log4net.config at buildtime depending on the build configuration chosen.
This is done by adding a build target to your csproj file like so:
<Target Name="BeforeBuild">
<Delete Files="$(ProjectDir)log4net.config" />
<Copy SourceFiles="$(ProjectDir)log4net.$(Configuration).config"
DestinationFiles="$(ProjectDir)log4net.config" />
</Target>
(you may have to modify the paths in the script depending on where in the solution your config files are)
You can find more information on MSBuild and manipulating your .csproj file here and here

VS 2012 Publishing Profiles and Copy Files Using MSBuilld Commands

I've set up asp.net website on Azure with TFS online for source control using VS 2012. I'm trying to copy files using VS 2012 new publishings profiles and MSBuild. Reading this article Visual Studio 2012 Web Deployment Projects are Dead – Long Live Publishing Profiles, in which Doug says you can use build scripts in your publishing profile.
So I setup a test that works in my .csproj on my local build. I'm just simply copying the robots.txt file from the root directory to the css directory. Here is my test. I set my pubxml in the TFS Build Process template under process > 6. Publishing -- Azure Website, Web Deploy Pubish Profile.
<Target Name="AfterBuild">
<Copy SourceFiles="$(ProjectDir)robots.txt" DestinationFolder="$(ProjectDir)css\" />
</Target>
I dropped this Code into my my pubxml file and I get a big nothing. What am I doing wrong?
Is it possible to copy files afterbuild on Azure?
Additional Information
The log file contains these lines so I'm sure the publishing profile is running.
AfterBuild:
Creating directory "C:\a\src\...\css".
Copying file from "C:\a\src\...\robots.txt" to "C:\a\src\...\css\robots.txt".
Here are the build steps that Azure's default build template uses:
ValidateSolutionConfiguration:
PrepareForBuild:
CoreCompile:
_CopyFilesMarkedCopyLocal:
CopyFilesToOutputDirectory:
GenerateTargetFrameworkMonikerAttribute:
CoreCompile:
_CopyFilesMarkedCopyLocal:
CopyFilesToOutputDirectory:
_CopyWebApplicationLegacy:
ValidateGlobalPackageSetting:
CollectFilesFromIntermediateAssembly:
CollectFilesFromContent:
CollectFilesFromIntermediateSatelliteAssembliesWithTargetPath:
CollectFilesFromReference:
CollectFilesFromAllExtraReferenceFiles:
CollectFilesFrom_binDeployableAssemblies:
PipelineCollectFilesPhase:
ExcludeGeneratedDebugSymbol:
PreTransformWebConfig:
TransformWebConfigCore:
PostTransformWebConfig:
PreProfileTransformWebConfig:
PipelineTransformPhase:
ProcessPublishDatabaseSettings:
PreAutoParameterizationWebConfigConnectionStrings:
AutoParameterizationWebConfigConnectionStringsCore:
PostAutoParameterizationWebConfigConnectionStrings:
PipelineMsdeploySpecificTransformPhase:
ValidatePublishProfileSettings:
CopyAllFilesToSingleFolderForMsdeploy:
PipelineCopyAllFilesToOneFolderForMsdeploy:
Package:
GenerateMsdeployManifestFiles:
PackageUsingManifest:
GenerateSampleDeployScript:
PipelineDeployPhase:
AfterBuild:
So it looks like Azure packages all the files up during the "31. CopyAllFilesToSingleFolderForMsdeploy" step. It would appear that running copy during the AfterBuild step is to late. I moved the Copy command to the target "BeforeBuild" but the files are still not ending up in the CopyAllFilesToOneFolderForMsdeploy step.
Thanks to Sayed Ibrahim Hashimi for his article How to compress CSS/JavaScript before publish/package for helping me solve this.
It's possible to copy directly Package Temp Directory. I ended up adding this target to my publishing profile (pubxml) file. After the "CopyAllFilesTOSingleFolderForMsdeploy" step finishes this step will run which will copy a file from one part of the solution into the destinationfolder you specify.
<Target Name="AdditionalFilesForPackage" AfterTargets="CopyAllFilesToSingleFolderForMsdeploy">
<Copy SourceFiles="$(ProjectDir)robots.txt" DestinationFolder="$(_PackageTempDir)\css\" />
</Target>

Merge Publisher - what does <file action="Copy"> actually do in CruiseControl.Net?

I inherited a project that runs TestComplete scripts from CruiseControl.
For each Script there is an entry in CCnet.Config and each entry ends with the following:
<publishers>
<merge>
<files>
<file action="Copy">
C:\Test\Log\TestCompleteResult\TestWebLog.mht
</file>
</files>
</merge>
<xmllogger />
<statistics />
Which I assumed copies the TestComplete log to that location. However, if I change the location (i.e. to C:\test\log2\TestWebLog.mht), the file still ends up in C:\Test\Log\TestCompleteResult. I have tried shutting down CruiseControl, rebooting the system etc. and the file still ends up in the same location.
I have deleted the directory and file, checked the time stamp and looked at the log file. All indicate that it is a new file created by the most recent run of the TestComplete script, but it always gets put in the same location: C:\Test\Log\TestCompleteResult\TestWebLog.mht.
Is there some place else this path could be defined?
From the CruiseControl.NET Wiki :
Copy: instead of merging the data into the build log, it will copy the specified files into a "build" folder under the artefacts folder for the project
In ccnet.config you can specify an artifact directory for each project into which the build results will be placed.
<project name="Project">
<artifactDirectory>C:\ProjectDir\artifacts</artifactDirectory>
...
</project>
The default merge action is to combine the specified file with the result.xml found in the artifact directory.
The "Copy" merge action copies the specified file into the artifactdirectory\Build folder.
The file you specify in the <file>...</file> tags is the source file that will be copied to the artifact folder.
The <merge> publisher includes an existing file in the build report. If you want to change the location in which the file is generated, you need to change the task configuration (i.e. in the place where TestComplete gets actually invoked).

Resources