How to Configure Bamboo to Build NUnit Tests? - c#

I am working on setting a project to use bamboo for CI testing, but have hit a hitch when attempting to compile unit tests. We are using the .NET framework 4.5 and NUnit v2.6.3.13283. When I am in bamboo, I have set up the specific job to check out the source code when a new commit is pushed, and then use MSBuild to build the code. Unfortunately, when it reaches this second step, it decides that it no longer understands what NUnit is.
I have the nunit.framework.dll in the same directory (bin\Debug) as the class .dll, so I'm definitely confused as to how I should go about having MSBuild work out building the NUnit tests.
Any help would be appreciated.
EDIT: Error log for those not faint of heart.
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Csc.exe /noconfig
/nowarn:1701,1702 /nostdlib+ /platform:AnyCPU /errorreport:prompt
/warn:4 /define:DEBUG;TRACE
/reference:c:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll
/reference:C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll
/reference:"C:\build-dir\UCL-UNL-JOB1\Unit Class
Library\bin\Debug\Unit Class Library.dll" /debug+ /debug:full
/filealign:512 /optimize-
/out:obj\Debug\UnitClassLibraryNUnitTests.dll /target:library
AngleNUnitTests.cs
"C:\Users\Bamboo\AppData\Local\Temp.NETFramework,Version=v4.5.AssemblyAttributes.cs"
AngleNUnitTests.cs(5,7): error CS0246: The type or namespace name
'NUnit' could not be found (are you missing a using directive or an
assembly reference?)
[C:\build-dir\UCL-UNL-JOB1\UnitClassLibraryNUnitTests\UnitClassLibraryNUnitTests.csproj]
AngleNUnitTests.cs(12,10): error CS0246: The type or namespace name
'Test' could not be found (are you missing a using directive or an
assembly reference?)
[C:\build-dir\UCL-UNL-JOB1\UnitClassLibraryNUnitTests\UnitClassLibraryNUnitTests.csproj]
etc.

You need to use a previous task to MSBuild one (Maybe you could consider to use the VisualStudio Task it works like a charm).
This previous task is a Command Task, it will update the Dlls related to the NuGet Package, in order to achieve it:
Create a New Executable on Bamboo, pointing to the nuget.exe file (if you don't have it you could download from https://www.nuget.org/
Create a New Command Task with the executable your created on the previous step.
On the Argument field: "restore YourSolution.sln"
In my approach I am using a VisualStudio task and after this one a MSTest Runner task.

When using Nuget with a source code repository, you have a couple of options.
1) check in your nuget executable to source code and create a bamboo command task that calls that location relative to the build directory, ${bamboo.build.working.directory}\tools\Nuget.exe.
2) Install the Nuget exe directly on the build server. Then you can create a new executable on Bamboo that you can reference in any task.
To create a new executable for use in tasks, use this - https://confluence.atlassian.com/display/BAMBOO/Defining+a+new+executable+capability

I guess you are using NuGet?
If so, you need to enable NuGet Package restore, because MSBuild does not know how to resolve these NuGet packages. This will create a .nuget directory in your solution which needs to be pushed the repository bamboo uses for the build.
Second problem I encountered when configuring the NUnit test runner with bamboo: the nunit-console.exe uses .NET Framework 3.5 which was not installed on my build server.

Related

TeamCity C# build failed most likely because of nuget restore issue

I am trying to set up a new TeamCity build job and am facing a build issue.
The build failed because of missing references within ResolveProjectReferences step.
For instance :
JSonTools\JSonHelper.cs(21, 7): error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
Prior to the build step, 2 restore nuget steps are set up and both ran successfully (one for sdk like project and the second for previous version, in this order)
When I run my solution on the agent and restore nuget packages through VS it is working fine (and TC job will run successfully if made on the same agent)
I noticed the dlls pulled during the restore nuget steps are in the path of my sln, while it seems to be require on others path.
Several VCS are set for this job and from what i can see/understand, the failing projects seem to require the dll to be in their own path under the packages folder.
\this
\is
\my
\path
Project1.csproj
packages\ (<- contains all the Dlls)
\folder1
\Project2.csproj
\Project3.csproj
\packages\ (I have the feeling some Dlls should be here but the folder doesn't exist)
\folder2
\Project4.csproj
\packages\ (same as previously)
Did I missed something ?
Any help would be appreciated.
Thanks,
Cervelle

Assembly references of PackageReference missing when building with jenkins and devenv.com

I'm building a solution that contains a class library, a UnitTest Project and a .vdproj setup project. Because MSBuild cannot handle vdproj I'm using devenv.com. I'm calling C:\NuGet\nuget.exe restore "%WORKSPACE%\solution.sln" -ConfigFile C:\NuGet\NuGet.config before the build starts and build with "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\devenv.com" rotring.tacton.export.sln /build "ci".
After that I execute the tests with "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" "%WORKSPACE%\testproject.test\bin\ci\tests.dll".
The nuget restore command tells me that every package has been restored correctly and to the right place:
Added package 'package.1.9.11' to folder 'C:\dev\workspace\solution\packages'.
But still I'm getting the error:
error CS0234: The type or namespace name 'sometype' does not exist in the namespace 'somenamespace' (are you missing an assembly reference?)
Local builds just work fine even when I'm executing the console build mentioned above manually.
Do I need to restore the packages somehow with devenv.com? Isn't the advantage of PackageReference that all packages are stored at the same place compared to packages.config?
Update: I managed to find a partly myself. One thing was that my Test-Project was not migrated to PackageReference and caused an error.
However I was able to build the solution by first restoring the packages with MSBuild:
"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe" /t:Restore /p:RestoreConfigFile="C:\NuGet\NuGet.config"
And then building the solution with devenv.com:
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\devenv.com" solution.sln /build "ci"
Now the only problem I face is that msbuild only restores the packages from the main project and doesn't care about the Test-Project.

AppVeyor: Build Failed : Cant locate NUnit assembly

I'm having trouble building these simple tests using NUnit. Project passes the build using MStest, but as soon as I switch to NUnit it fails the build.
The error I'm getting during build process is basically:
Could not resolve this reference. Could not locate the assembly "nunit.framework". Check to make sure the assembly exists on disk. If
this reference is required by your code, you may get compilation
errors.
I have NUnit 3.5 downloaded from NUGET and added the .dll to my references, and still nothing. I also have also made sure the properties of that reference have the copy local property set to true.
Here is my build log URL on AppVeyor (https://ci.appveyor.com/project/ReevMich/traviscitest/build/1.0.26)
This is my appveyor.yml contents if that helps.:
version: 1.0.{build}
branches:
only:
- master
- dev
configuration: Debug
before_build:
- nuget restore
build:
verbosity: minimal
project: FizzBuzz.sln
test:
assemblies:
- '**\*.Test.dll'
artifacts:
- path: '**\*.nupkg'
name: NuGet
Remove packages folder from your repository (it doesn't contain assemblies anyway), so it's always re-created during the build with nuget restore.

Missing Automation from namespace 'System.Management'. Missing assembly reference

System: Windows 7 Professional 64 bit, PowerShell v 2.0, no Visual Studio (can't be installed and others too)
Trying to run PowerShell from C#. This is the code snippet:
using System;
using System.Management.Automation;
class Hello {
static void Main(string[] args) {
PowerShell ps = PowerShell.Create();
ps.AddCommand("Get-Process");
Console.WriteLine("Process Id");
Console.WriteLine("----------------------------");
foreach (PSObject result in ps.Invoke()) {
Console.WriteLine(
"{0,-24}{1}",
result.Members["ProcessName"].Value,
result.Members["Id"].Value);
}
}
}
Error:
e:\foo.cs(2,25): error CS0234: The type or namespace name 'Automation' does not exist in the namespace 'System.Management' (are you missing an assembly reference?)
Since no Visual Studio is there, I am running code in raw manner. Because of error, I downloaded dll from http://www.dll-found.com/system.management.automation.dll_download.html and placed in dir as per instruction. After rebooting machine, there was no success.
First, I want to ask a general question. How to install missing assembly or dll file (only), because for some you might have to install whole Windows or PowerShell SDK or .NET Framework.
EDIT
I have place downloaded dll file in C:\Windows\SysWOW64, C:\Windows\system32, C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5 and C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0.
I am compiling using:
C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe /target:exe /out:E:\foo.exe E:\foo.cs
WARNING: Never ever download DLLs from random websites in any sane situation. Use NuGet packages (or whatever your preferred package manager is for your project) whenever possible. If a DLL is not found, there is almost always a good reason for it, and you need to find out what it is and fix it, not just get the DLL from the internet.
If you have this problem after re-targeting an old project to, for example, .NET 4.8, then it is because NuGet package names have changed.
Uninstall the package System.Management.Automation
Install the package Microsoft.PowerShell.5.1.ReferenceAssemblies (NuGet)
This package name appears in the documentation of classes in the namespace System.Management.Automation.
NuGet worked for me.
PM> Install-Package System.Management.Automation.dll -Version 10.0.10586
You must use /reference command line parameter to csc.exe, described in MSDN:
C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe /reference:system.management.automation.dll /target:exe /out:E:\foo.exe /E:\foo.cs

Visual Studio Online CI Nunit references not resolved during build

I have been trying to get my solution to build in a CI configuration using Visual Studio Online and the hosted build controller.
I have created a folder in the root of my workspace with the required NUnit binaries as per these guidelines.
I have also referred to these previous questions where users had issues trying to accomplish the same thing:
Visual Studio Online CI Nunit Tests not found during build
What else is needed to get the Hosted Build Controller to run my NUnit tests
I have the "NUnit Test adapter for VS2012 and VS2013" package installed in all of my test projects.
The error messages in my build log are like this:
Tracking_works_when.cs (35): The type or namespace name 'TestAttribute' could not be found (are you missing a using directive or an assembly reference?)
The type 'TestAttribute' is one of several missing ones, including 'Test', 'TestFixture' and 'TestFixtureAttribute'.
There is also the following warning:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets (1605): Could not resolve this reference. Could not locate the assembly "nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
The same warning is repeated for "nunit.core.interfaces" and "nunit.core".
Question:
What am I missing? Why are my NUnit binaries not being identified within the hosted build environment and my tests run automatically?

Categories