Cannot integrate Gallio MBUnit with Team City - msbuild

I have been trying to get my MBUnit tests suite to work on Team City for many days now without any success.
My solution builds no problem. The program is with my tests. After googling for Gallio integration with Team City I tried many ways to make this thing work and I think I am close but need help.
I have included the gallio bin directory to my repository and also on my TC Server.
Here is my build runner set up in Team City :
Build runner : MSBuild
Build file path : Myproject.msbuild
Targets : RebuildSolution RunTests
Here is Myproject.msbuild file I created and included in the Source control trunk directory :
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- This is needed by MSBuild to locate the Gallio task -->
<UsingTask AssemblyFile="C:\Gallio\bin\Gallio.MSBuildTasks.dll" TaskName="Gallio" />
<!-- Specify the tests assemblies -->
<ItemGroup>
<TestAssemblies Include="C:\_CBL\CBL\CoderForTraders\Source\trunk\UnitTest\DomainModel.Tests\bin\Debug\CBL.CoderForTraders.DomainModel.Tests.dll" />
</ItemGroup>
<Target Name="RunTests">
<Gallio IgnoreFailures="false" Assemblies="#(TestAssemblies)" RunnerExtensions="TeamCityExtension,Gallio.TeamCityIntegration">
<!-- This tells MSBuild to store the output value of the task's ExitCode property into the project's ExitCode property -->
<Output TaskParameter="ExitCode" PropertyName="ExitCode"/>
</Gallio>
<Error Text="Tests execution failed" Condition="'$(ExitCode)' != 0" />
</Target>
<Target Name="RebuildSolution">
<Message Text="Starting to Build"/>
<MSBuild Projects="CoderForTraders.sln"
Properties="Configuration=Debug"
Targets="Rebuild" />
</Target>
</Project>
Here are the errors displayed by Team City :
error MSB4064: The "Assemblies" parameter is not supported by the "Gallio" task. Verify the parameter exists on the task, and it is a settable public instance property
error MSB4063: The "Gallio" task could not be initialized with its input parameters.
Thanks for your help

The Assemblies attribute has been renamed to Files.
Documentation here: http://www.gallio.org/api/html/T_Gallio_MSBuildTasks_Gallio.htm

Related

MC.exe in msbuild

How do I compile with mc.exe in the correct way. Currently I have a build step which runs the relevant command but looking at developer network
There seems to be a better way.
I am not a expert with msbuild so please excuse how easy this question is. Googling has revealed no help
<Project
DefaultTargets="Build"
ToolsVersion="14.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Message Source Files">
<Extensions>mc;</Extensions>
<UniqueIdentifier>{B796B525-44D3-4260-8C76-705DBADA1043}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<MessageCompile Include="a.mc">
<GenerateBaselineResource>true</GenerateBaselineResource>
</MessageCompile>
</ItemGroup>
<Target Name="Build">
<DontKnowWhatGoesHere Sources="#(MessageCompile)"/>
</Target>
</Project>
MSBuild build are usually extended via .targets files, that have to be included in the project, and they extend the existing build proces. The WDK tasks for MSBuild page confirms this:
These command-line tools need to be exposed to MSBuild as tasks (contained in targets) so that they can be run during the build process.
The WDK MSDN page also has a help page on Windows driver targets:
The WindowsDriver.Common.targets, WindowsDriver.masm.targets, and WindowsDriver.arm.targets files provide the targets that are necessary to build a driver.
A quick grep in my C:\Program Files (x86)\Windows Kits\10\build directory showed that the MessageCompile target (the step that actually processes the MessageCompile items) is defined in the build\WindowsDriver.Common.targets file.
After importing the targets in your project you can do one of the following:
<Import
Project="C:\Program Files (x86)\Windows Kits\10\build\build\WindowsDriver.Common.targets" />
<!-- Option A: -->
<Target Name="Build" DependsOnTargets="MessageCompile">
<!-- no need to do anything, the dependency target should do the work -->
</Target>
<!-- Option B: -->
<Target Name="Build" DependsOnTargets="MessageCompile">
<!-- Use the Mc task which is the actual wrapper around the .exe,
see the .common.targets file for the list of all parameters -->
<Mc
Sources ="#(MessageCompile)"
ToolExe ="$(MessageCompileToolExe)"
ToolPath ="$(MessageCompileToolPath)"
Generated
/>
</Target>

MSBuild /m:4 fails because it builds the same project twice

My team has a large solution (~500 csproj's). We use VS2012, and build using TFS Build, which uses MSBuild 4. Currently we build serially, but we want to build in parallel (using msbuild /maxcpucount:4). However, when I try it on my 4-proc machine, I get a weird failure:
11:2>CSC : fatal error CS0042: Unexpected error creating debug information file 'C:\Common\obj\Debug\Common.PDB' -- 'C:\Common\obj\Debug\Common.pdb: The process cannot access the file because it is being used by another process. [C:\Common\Common.csproj]
Looking at the log, 2 msbuild nodes were trying to build that same csproj, and thus colliding on writing some output:
10>Project "C:\Utils\Utils.csproj" (10) is building "C:\Common\Common.csproj" (11) on node 4 (default targets).
46:2>Project "C:\Objects\Objects.csproj" (46:2) is building "C:\Common\Common.csproj" (11:2) on node 1 (default targets).
Why would MSBuild try to build the same project twice?
Cause: Someone was calling <MSBuild Projects="Common.csproj" Properties="..." />. Then, MSBuild thinks that it should build Common.csproj again with those different properties, and it happened to occur at the same time with the regular compilation of Common.csproj.
Fix: Call <MSBuild ... /> without those unneeded properties.
Test:
Common.targets
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<Message Importance="high" Text="Build in $(MSBuildThisFile)" />
</Target>
<Target Name="After" DependsOnTargets="Build">
<Message Importance="high" Text="After in $(MSBuildThisFile)" />
</Target>
</Project>
Other.targets
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<Message Importance="high" Text="Build in $(MSBuildThisFile)" />
<MSBuild Projects="common.targets" Targets="Build" /> <!-- regular builds -->
<MSBuild Projects="common.targets" <!-- custom invocation with properties -->
Targets="After"
Properties="myprop=myvalue"
/>
</Target>
</Project>
Run:
> msbuild other.targets /clp:verbosity=minimal
Build in other.targets
Build in common.targets
Build in common.targets <<<< Common.targets Build is invoked again
After in common.targets
And indeed, removing Properties="myprop=myvalue" solves the issue.
I found someone had added two project references (from the same project) and that apparently caused msbuild to build twice also.. something to watch out for

MSBuild hangs after NUnit is finished

I'm trying to set up a MSBuild with NUnit as unit test driver but the script keeps hanging after NUnit is done. It doesn't seem to finalize its work and let MSBuild get on with its job.
I'm working in .NET 4.0 and using NUnit 2.5.8.
If I run the test manually or using the gui (either VS2010 or NUnit) it works fine but not when called by MSBuild.
I'd appreciate any help with error finding or just a heads up on where to looks for answers.
The manual command looks like this:
C:\....>nunit\nunit-console.exe buildbinaries\YYYY.XXXX.Extractor.Test.IntegrationTest.dll /xml=nunit.xml
and the abbreviated MSBuild:
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- define folders for build output and reports -->
<PropertyGroup>
<BuildPath>buildbinaries\</BuildPath>
<ReportPath>buildreports\</ReportPath>
<ReleaseFolder>release_artefacts\</ReleaseFolder>
<PublishFolder>c:\ZZZ Applications\published builds\</PublishFolder>
<DeploymentFolder>\\seldclq99\ZZZ_Costanza_Dev$\</DeploymentFolder>
</PropertyGroup>
<PropertyGroup>
<!-- specify assemblies that should be included in coverage report -->
<NCoverAssemblyList>YYYY.XXXX.Extractor.Business.dll; YYYY.XXXX.Extractor.Common.dll YYYY.XXXX.Extractor.Configuration.dll YYYY.XXXX.Extractor.DAL.Access.dll YYYY.XXXX.Extractor.DAL.Facade.dll YYYY.XXXX.Extractor.Service.Contracts.dll YYYY.XXXX.Extractor.Service.dll YYYY.XXXX.Extractor.Service.Host.WebHost.dll YYYY.XXXX.Extractor.ServiceGateway.dll</NCoverAssemblyList>
</PropertyGroup>
<!-- define item group for deliverables -->
<ItemGroup>
<Binaries Include="$(BuildPath)/**/*.*" Exclude="$(BuildPath)nunit*" />
</ItemGroup>
<!--
This is the default target that will be executed if MSBuild is not started
with a specific target (this is decided by the DefaultTargets attribute in
the root element of this XML document)
-->
<Target Name="BuildAndTest">
<CallTarget Targets="SetupDirs" />
<CallTarget Targets="Build" />
<CallTarget Targets="UnitAndIntegrationTest" />
<CallTarget Targets="FxCop" />
<CallTarget Targets="CopyToReleaseFolder" />
</Target>
<!-- Setup folders used during the build -->
<Target Name="SetupDirs">
<RemoveDir Directories="$(ReportPath);$(BuildPath);$(ReleaseFolder)" ContinueOnError="true"/>
<MakeDir Directories="$(ReportPath);$(BuildPath);$(ReleaseFolder);$(AssemblyVersionFolder)" ContinueOnError="true"/>
</Target>
<Target Name="Build">
<!-- build the software using msbuild -->
<!-- Build error in the Install build-->
<MSBuild ContinueOnError="true" RebaseOutputs="false" Targets="Clean;Rebuild" Projects="YYYYXXXXExtractor.sln" Properties="Configuration=Release;OutDir=..\$(BuildPath)" />
</Target>
<!--Run the coverage stats-->
<Target Name="UnitAndIntegrationTest">
<Exec Command="nunit\nunit-console.exe buildbinaries\YYYY.XXXX.Extractor.Test.IntegrationTest.dll /xml=$(ReportPath)nunit.xml "/>
<CallTarget Targets="UnitTest" />
</Target>
<Target Name="UnitTest">
<Exec Command="nunit\nunit-console.exe buildbinaries\YYYY.XXXX.Extractor.Test.UnitTest.dll /xml=$(ReportPath)nunit.xml"/>
</Target>
<!-- Run FxCop -->
<!-- The ForceError.bat fires if the xml file is not found... aka an error was found -->
<!-- The quiet command forces an Xml file ONLY if warnings or Errors are found -->
<Target Name="FxCop">
<Exec Command="..\tools\fxcop\FxCopCmd.exe /p:..\FxCopSettings.FxCop /o:$(ReportPath)fxcop.xml" />
<Exec Condition="Exists('$(ReportPath)fxcop.xml')" Command="..\tools\fxcop\FX_Cop_Failed_Rule_Checks.bat" />
<!--STATS: Run again but don't fail and this time run for all rules.-->
<Exec Command="..\tools\fxcop\FxCopCmd.exe /p:..\FxCopSettingsALLRULES.FxCop /o:$(ReportPath)fxCopAllRules.xml" />
</Target >
I had the same problem with NUnit 2.5.8. There is some discussion of this at the nunit site about the test process hanging. I switched to NUnit 2.5.7 and the problem went away.
It looks like this was fixed a couple of weeks ago in 2.5.9.
I have noticed similar behaviour on out build server since upgrading to .NET 4. MsBuild seems to intermittently hang on either NUnit, FxCop or Dotcover EXEC commands. If you check task manager the process for externally executed command (e.g. Nunit.exe) is still hanging around. If you manually kill the process MsBuild continues on it's merry way - which is far from ideal!
Could this be a bug in the latest version of MsBuild? Our build server was running quite happily until the .NET 4 upgrade.
If you run ProcessExplorer on your server you will notice that an out of band process called nunit-agent is spawned which ends up blocking the nunit runner.
I have not validated that this is fixed in 2.5.9, but it might be some info that could be helpful.

MSBuild CreateItem condition include based on config file

I'm trying to select a list of test dlls that contain corresponding config files
MyTest.Tests.dll
MyTest.Tests.config
I have to use a createItem as the dlls are not available at the time of the script loading
<CreateItem Include="$(AssemblyFolder)\*.Tests.dll"
Condition="???"
<Output TaskParameter="Include" ItemName="TestBinariesWithConfig"/>
</CreateItem>
Is there a condition I can use or is this the wrong approach?
Thanks
Mac
EDIT:
ok, to clarify, I need to construct a xUnit.Net project file. I need to do this because I'm running the tests through the xUnit.Console runner via nCover (don't ask!) but the long and short of it is I can only use a project file. The problem I'm having is when I have a test dll with an associated .config file. Without the config file, the test runner will fail.
This means I need to conditionally add an extra attribute (config-file) in the test project file.
The project template file:
<?xml version="1.0" encoding="utf-8"?>
<xunit>
<assemblies>
<!-- SAMPLE <assembly filename="Tests.dll" shadow-copy="false" config-file="Tests.dll.config" /> -->
<!-- #TARGETS# -->
</assemblies>
</xunit>
The FileUpdate task for the test dlls with no config file.
<FileUpdate
Files="$(AssemblyFolder)\$(XUnitProjectFileName)"
Regex="<!-- #TARGETS# -->"
ReplacementText="<!-- #TARGETS# -->%0D%0A<assembly filename='$(AssemblyFolder)\%(TestBinaries.FileName)%(TestBinaries.Extension)' shadow-copy='false' />"
/>
So I need a way to conditionally add the extra attribute in the FileUpdate task depending on whether there is a corresponding config file for the test dll.
You could just use the MSBuild Task output as a source for your CreateItem Task.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ProjectReferences Include="*.*proj" />
</ItemGroup>
<Target Name="BuildMyProjects">
<MSBuild
Projects="#(ProjectReferences)"
Targets="Build">
<Output
TaskParameter="TargetOutputs"
ItemName="AssembliesBuiltByChildProjects" />
</MSBuild>
</Target>
<Target Name="AddConfigMetadata" DependsOnTargets="BuildMyProjects">
<CreateItem
Include="#(AssembliesBuiltByChildProjects)"
AdditionalMetadata="config-file=%(Identity).config">
<Output
TaskParameter="Include"
ItemName="MySourceItemsWithMetadata" />
</CreateItem>
</Target>
<Target Name="WhatEverYouLikeToDo" DependsOnTargets="AddConfigMetadata">
<Message Text="%(MySourceItemsWithMetadata.config-file)" />
</Target>
</Project>
Your problem discription isn't really clear to me, but your .Tests.dll's should always be available because you should build your project first before testing it. Whenever you've build your project, you can run the CreateItem task. The CreateItem is a good approach to retrieve the .dll's but you don't need a condition for it.
So in your build file you should have something like this:
- Build project/solution
-> .dll's will be created
- Execute CreateItem
- Do something with the Item
With this awnser I'm assuming you're trying to automate your tests?

Unable to publish using msbuild or aspnet_compiler using cc.net

I am trying to automate publishing a project having many solutions in cc.net. I am using msbuild which in turn calls a aspnetcompiler xml file. Problem is my directory contains many solutions and when I run aspnetcompiler it gives me the following error.
errorASPCONFIG: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS
I have tried all possible solutions given at many forums. But I am confused how to explicitly tell aspnet_compiler to execute a particular project out of 20 projects.
I am using the ccnet build to call aspnet complier
<msbuild>
<executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable>
<!--msbuild exe directory -->
<workingDirectory>C:\cc\test\code\</workingDirectory>
<!--your working directory -->
<projectFile>C:\Program Files\CruiseControl.NET\server\AspNetCompilerConfiguration.xml</projectFile>
<!--the configuration xml file which will hold AspNetCompiler lines-->
<logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
</msbuild>
this is my AspNetCompilerConfiguration.xml file
<Project
xmlns = "http://schemas.microsoft.com/developer/msbuild/2003"
name = "AspNetPreCompile"
DefaultTargets = "PrecompileWeb">
<Target Name = "PrecompileWeb">
<AspNetCompiler
VirtualPath = "test"
PhysicalPath = "C:\cc\test\code\"
TargetPath = "C:\cc\testitr\deploy\"
Force = "true"
Debug = "true"
Updateable = "true"/>
</Target>
</Project>
Now I want to run C:\cc\test\code\Com.Project1.sln. but i dont know how to tell aspnet compiler. Any idea how to do this and then publish this.
First of all: you can't publish website by scirpt with aspnet_compiler but you can (Release-mode-)compile website which is generally the same thing. Or you can use MsBuild by the way I describe in this post.
I recommend you to group your ASP.NET Websites to solution files and build them. Then you have less params and you can test the build with Visual Studio.
Here is how you can use some params in your cc.net build file for msbuild-scirpt:
<msbuild>
<executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable>
<!--msbuild exe directory -->
<workingDirectory>C:\cc\test\code\</workingDirectory>
<!--your working directory -->
<projectFile>C:\Program Files\CruiseControl.NET\server\AspNetCompilerConfiguration.xml</projectFile>
<!--the configuration xml file which will hold AspNetCompiler lines-->
<logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
<!--Build arguments. You can have multiple projects or msbuild sections in cc.net.config-->
<buildArgs>/p:Configuration=Debug;MyAttribute1=MyValue1;MyAttribute2=MyValue2;</buildArgs>
<!--targets, if not default (here PrecompileWeb) -->
<targets>Build;Analyze</targets>
</msbuild>
Then you can modify your AspNetCompilerConfiguration.xml (better name in my opinion would be something like MyWebSites.msbuild) to take params:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" name = "AspNetPreCompile" DefaultTargets = "PrecompileWeb">
<!--Conditions are params from ccnet.config (or command line)-->
<PropertyGroup Condition="'$(MyAttribute1)' == MyValue1" >
<MySolution>c:\mything.sln</MySolution>
</PropertyGroup>
<PropertyGroup Condition="'$(MyAttribute1)' != MyValue1" >
<MySolution>c:\some_other.sln</MySolution>
</PropertyGroup>
<!--This way you could import other msbuild-scirpts to manage separate files-->
<!--<Import Project="Morexml.msbuild"/>-->
<Target Name="Build">
<Exec Command="echo hello world 1!"/>
<MSBuild Projects="$(MySolution)" Targets="Rebuild" ContinueOnError="false" StopOnFirstFailure="false" />
</Target>
<Target Name="Analyze">
<Exec Command="echo hello world 2!"/>
</Target>
<!--default, for example, here call some tasks -->
<!--default is not used when targets are specified -->
<Target Name="PrecompileWeb">
<CallTarget Targets="Build" />
<CallTarget Targets="Analyze" Condition="'$(MyAttribute2)' != 'MyValue2'" />
</Target>
</Project>
You can configure your solution .sln-file with Visual Studio or Notepad. However it should have your websites, something like this:
Project("{ABCD1234-7377-472B-9ABA-BC803B73C123}") = "MyWebSite", "http://localhost/MyWebSite", "{12345678-5FD6-4177-B210-54045B098ABC}"
ProjectSection(WebsiteProperties) = preProject
Debug.AspNetCompiler.VirtualPath = "/MyWebSite"
Debug.AspNetCompiler.PhysicalPath = "..\..\MyWebSite\"
Debug.AspNetCompiler.TargetPath = "C:\MyPublishedWebsite\"
Debug.AspNetCompiler.Updateable = "false"
Debug.AspNetCompiler.ForceOverwrite = "true"
...
There you can see the properties. There is no need for IIS any configuration. (Just check your released Web.Config (Release/Debug, etc. settings) or maybe use some msbuild-Target to handle that.)
Hope this helps!