Gitlab CI with C# build - c#

I have created a C# project (C# 7.0 & .net framework 4.7.2) and also added some unit tests (NUnit 3.11.0).
This code is stored in a Gitlab repo and I can run the tests and build locally. But now I want to automate this via the Gitlab CI. According to this stackoverflow post and a lot of articles on the internet you should create your own runner on a Windows machine.
But most of those answers are already pretty old and the Gitlab CI can now work with Docker images. But then I arrive at my problem. What image should I use for this runner? I've tried microsoft/dotnet-framework and microsoft/dotnet but those didn't work.
The microsoft/dotnet-framework gives the error message: No such image: microsoft/dotnet-framework
and the microsoft/dotnet images doesn't contain the .net 4.7.2 library so it can't be used for a build.
Gitlab CI + Docker image + C# build?
Is it still not possible to create a Gitlab CI runner with a Docker image for a C# build (console application)? Or am I just doing something wrong here?
My current .gitlab-ci.yml
image: microsoft/dotnet-framework
stages:
- build
before_script:
- 'dotnet restore'
app-build:
stage: build
script:
- 'dotnet build'
only:
- master
Update
Do thanks to #Andreas Zita I now have an Image (dsfnctnl/gitlab-dotnetcore-builder:0.15.0). Unfortunately this gives me the same error as the microsoft/dotnet. This is probebly an error in my build script (or so I hope), but I cannot seem to find what it is.
The error:
$ dotnet restore
Nothing to do. None of the projects specified contain packages to restore.
$ dotnet build
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Nothing to do. None of the projects specified contain packages to restore.
/usr/share/dotnet/sdk/2.1.500/Microsoft.Common.CurrentVersion.targets(1179,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.7.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [/builds/test/TestProject.csproj]
/usr/share/dotnet/sdk/2.1.500/Microsoft.Common.CurrentVersion.targets(1179,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.7.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [/builds/test/TestProjectTests.csproj]
Build FAILED.

I think if you use .net framework 4.7.2 and you want to build painless, you need Windows with Visual Studio MSBuild.
Maybe it helps: https://medium.com/#n3d4ti/build-net-project-with-gitlab-ci-44e6c3562a8

Mono image is working for me to build the C# application in GitLab.
image: mono:4.4.0.182
stages:
- build
app-build:
stage: build
script:
- MONO_IOMAP=case xbuild/t:Build/p:Configuration="Debug"/p:Platform="x86"
myApp.sln
only:
- master
Platform might be change according to the build configuration like AnyCPU.

Related

Type CallerMemberNameAttribute exists in both System.Runtime 2.6.10 and mscorlib

I have a Class Library running on .Net 4.7. Attempting to upgrade this project to and SDK style i take the following steps in a terminal window (Im using Visual Studio 2022) and keep the target to 4.7
dotnet tool install --global Project2015To2017.Migrate2019.Tool
dotnet migrate-2019 wizard proj.csproj
(Received an error about the runtime not being installed on my machine so clicked the link and installed.)
I get some messages but no real errors as such e.g.
A better way to reference 'System.ComponentModel.Composition' assembly is using respective 'System.ComponentModel.Composition' NuGet package. It will simplify porting to other runtimes and enable possible .NET SDK tooling improvements.
and
Consider migrating to 'portable' debug type, cross-platform alternative to legacy Windows PDBs.
Number of these types of messages appear.
I load up the solution in VS 2022 and try to rebuild but some NuGet package errors occur so i restore all packages using the Nuget restore command.
Im now faced with the error
The type 'CallerMemberNameAttribute' exists in both System.Runtime VErsion 2.6.10.0 and mscorlib Version 4.0.0.0
This occurs on the line
public void DoSomething([CallerMemberName] string nm = "")
{}
Ive tried to reference this explicitly i.e. System.Runtime.CompilerServices.CallerMemberName but that didnt work and not entirely sure what i could attempt to resolve this?

Docker Image for Dotnet Core 2.2 seems to not exist in new repo

In visual Studio 2017, if you do a 'Add>Add Docker support' to a project, you get the old Repo:
microsoft/dotnet:2.2-aspnetcore-runtime location.
I figured, that must be now:
FROM mcr.microsoft.com/dotnet/core/runtime:2.2 AS base
And:
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
Doing that, allows it to build OK, however, when I run it to my utter amazement, I get:
It was not possible to find any compatible framework version
The specified framework 'Microsoft.AspNetCore.App', version '2.2.0' was not found.
- Check application dependencies and target a framework version installed at:
/usr/share/dotnet/
- Installing .NET Core prerequisites might help resolve this problem:
https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
- The .NET Core framework and SDK can be installed from:
https://aka.ms/dotnet-download
In the error log for the image when I try to run it..
Which implies that I shouldn't be using mcr.microsoft.com/dotnet/core/runtime:2.2 Because it doesn't include the DotNet Core 2.2 runtime! If not, they sure named it poorly!
Also, I just updated Visual Studio 2017, and it still generates a bogus Docker file that won't work, clearly, that needs fixed.
What is the correct Image for Dotnet Core 2.2?
It shouldn't matter, but I'm running this under Kubernetes / Docker Desktop
(Also, if I change the runtime to use the full version that I did the build on, it works! I just tried this after I wrote this...)

Gitlab CI and YAML for Dotnet Framework 4.6.1 - Selenium Automation

I am working on a Selenium Automation for a UnitTest Project in Dotnet Framework 4.6.1 and implementing Gitlab CI using a shared runner.
Created the YAML file and used image: mcr.microsoft.com/dotnet/sdk:3.1
The dotnet build command is failing with error message -
/usr/share/dotnet/sdk/3.1.406/Microsoft.Common.CurrentVersion.targets(1177,5): error MSB3644: The reference assemblies for .NETFramework,Version=v4.6.1 were not found. To resolve this, install the Developer Pack (sdk/Targetting Pack) for this framework version or retarget your application.
Any suggestion on -
Q1. How I can resolve this error so I can build my project? If I need to install the developer pack what should be the YAML step to install the developer pack for Dotnet 4.6.1?
Q2. If I use msbuild to build the project then the command is not being recognized. Is there any way to use msbuild command?
Note# These build commands are working in my local.
YAML
ERROR
Looking at the image on Docker hub, it doesn't appear to have a 4.6.1 version available. The available images are listed in the "Full Tag Listing" about half way down the page. If the 5.0 tags don't work for you, there's methods to contact Microsoft about that image under "Support" or "Feedback" at the bottom of the page.
https://hub.docker.com/_/microsoft-dotnet-sdk/

can nuget packages compiled against .net4.5 be referenced by dnxcore50

I'm compiling an application that targets the dnxcore50 only.
I'm attempting to reference a nuget package that I know works fine when run against dnx451. When I do dnx . run I get:
System.InvalidOperationException: Failed to resolve the following dependencies for target framework 'DNXCore,Version=v5.0':
it also suggests a dnu restore but the package is there
It does not work for this package clearly so under what circumstances will it (if any) ?
In order for it to work must the package manager build a version compiled against dnxcore50?
update
this chart makes things a bit clearer (copied from here)
No. dnxcore50 indicates you're running on DNX on top of .NET Core. The only assemblies you can load in .NET Core are those that target a compatible profile, in this case e.g. dnxcore50, dotnet, or one of the compatible portable profiles.
If you have an assembly compiled against the full .NET Framework (via net45, net451, etc.), it won't run when on .NET Core as the same APIs aren't available.

MSBUILD .NET v4 teamcity

I have installed TeamCity Professional 8.1.3 (build 30101) onto a clean box and I am trying to run a new build. I have copied over the msbuild tools from my local dev machine to the new server and placed them in the x86 folder. I have also installed the IIS web role, .net feature, registered IIS from the cmd line, and installed MSBUILD tools 2013. For some reason, I still am unable to compile anything. I get the following error
SGEN An attempt was made to load an assembly with an incorrect format:
C:\Windows\Microsoft.Net\assembly\GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll.
Is anyone familiar with this error? I am trying to build an app in .NET v4 using msbuild tools v4.
I was getting this error building a project that targeted .NET Framework 4.5.1. I resolved the issue by installing Microsoft .NET Framework 4.5.1 Developer Pack
You can get the SDK (aka Targeting Pack, aks Developer Pack) for other versions you may want to target at .NET SDKs and Downloads
The solution was installing VS2012 on my build machine. This may not be the most efficient, but it beats installing small packages and chasing around things that need to be registers in the GAC.

Categories

Resources