Build and Deploy C# Net Framework in GitLab CI CD - c#

Asking very generally as I am completely new to Gitlabs CI/CD and CI/CD in general.
I have implemented a C# Net Framework application in Visual Studio 2017 and manage it with Gitlab.
Now I want to automatically create a binary of that application with the GitLab CI/CD feature.
I already have a runner ( docker based on Windows) registered in GitLab and run jobs.
My current YAML file looks as following:
default:
image: ruby:2.7.2
job:
stage: build
only:
- branches
script:
- set -m
- echo "Start build"
- '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe" /p:Configuration=Release /clp:ErrorsOnly; Build "NameOfApplication.sln"'
artifacts:
expire_in : 1 days
paths:
- '.\IndoorNavigation\bin\Release'
How can I now get the artifact / binary MSBuild generates? It should show up in pipelines for download right? I already tried the artifacts option with different path unsuccessfully.
Would also be happy for links to good tutorials as I have not found any tutorial that helped me.
Edit: Output of the Job:
Running with gitlab-runner 14.3.1 (8b63c432)
on docker-runner 2tZDZ6cX
Preparing the "docker" executor
Using Docker executor with image ruby:2.7.2 ...
Pulling docker image ruby:2.7.2 ...
Using docker image sha256:e6c92ed2f03be9788b80944e148783bef8e7d0fa8d9755b62e9f03429e85a327 for ruby:2.7.2 with digest ruby#sha256:1dd0106849233fcd913b7c4608078fa1a53a5e3ce1af2a55e4d726b0d8868e2f ...
Preparing environment
00:01
Running on runner-2tzdz6cx-project-1235-concurrent-0 via d98bb3402720...
Getting source from Git repository
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /builds/user/NameOfApplication/.git/
Checking out 2e50e922 as master...
Skipping Git submodules setup
Executing "step_script" stage of the job script
Using docker image sha256:e6c92ed2f03be9788b80944e148783bef8e7d0fa8d9755b62e9f03429e85a327 for ruby:2.7.2 with digest ruby#sha256:1dd0106849233fcd913b7c4608078fa1a53a5e3ce1af2a55e4d726b0d8868e2f ...
$ set -m
$ echo "Start build" - '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe" /p:Configuration=Release /clp:ErrorsOnly; Build "NameOfApplication.sln"'
Start build - "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe" /p:Configuration=Release /clp:ErrorsOnly; Build "NameOfApplication.sln"
Uploading artifacts for successful job
00:01
Uploading artifacts...
WARNING: .\NameOfApplication\bin\Release: no matching files
ERROR: No files to upload
Cleaning up project directory and file based variables
00:01
Job succeeded

Related

"Failed to deploy project to App Engine Flex"

First time using GCP and I'm trying to upload a .NET project.
I cannot manage to publish the app using the integrated tools from Visual Studio, "Google Cloud Tools" and I get this message "Failed to deploy project to App Engine Flex".
I also tried using Cloud Run or the Google Cloud SDK Shell using gcloud app deploy app.yml but i get this error now:
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 1
I know it's coming from the Dockerfile but I don't know how to use and write it. Here it is:
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
COPY./sims/sims.csproj.sims/sims.csproj
COPY .sln./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o build --no-restore
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from= build./ build.
ENV ASPNETCORE_URLS = https://:8080
EXPOSE 8080
ENTRYPOINT ["dotnet", "sims.dll"]
Here's my .yaml file in case it might come from here:
runtime: aspnetcore
env: flex
# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/python/configuring-your-app-with-app-yaml
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
Do you have any advice ?
Also, concerning these two files, I don't even know if they're located in the right repository: project tree
Thanks for reading

error MSB1003: Specify a project or solution file. building a pipeline with azure and can't find csproj file

Hi I've got a solution that has multiple projects held within it where I'm hoping to automate the build and deployment of the webapplication within the project.
on my HD the dir looks like C:\Users\mleip\source\repos\edocs.utils.bluebeam-api\edocs.utils.bluebeam-api.Caller\edocs.utils.CDEComms , however, when I run the below yaml
i get
MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
variables:
buildConfiguration: 'Release'
steps:
- script: dotnet restore
- powershell: |
Write-Host "Your parameter is now: $env:Param"
Write-Host "When outputting standard variable build id: $(Build.BuildId)"
Write-Host "When outputting standard variable build id via env: $env:BuildNumber"
Write-Host "The repo name is: $(Build.Repository.Name)"
Write-Host "The build definition name is: $(Build.DefinitionName)"
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
- task: DotNetCoreCLI#2
inputs:
command: 'build'
projects: '**/edocs.utils.bluebeam-api.Caller/edocs.utils.CDEComms/edocs.utils.CDEComms.csproj'
So far I have tried several combinations of dir for where azure should locate the build file, however, each time it fails. The solution has several projects within it. CDEComms is the only project within that folder so I'm left quite confused as to what's going on.
I'm quite new to building pipelines and any help as to why this is failing would be greatly appreciated.
In order to narrow down the issue, try to simply specify **/*.csproj in the YAML file to check the build result. And set variable system.debug to True, to check whether the path is correct in C:\hostedtoolcache\windows\dotnet\dotnet.exe build {path}. Also, clone the repo to your local machine to run build it locally, to check the result.
From the description you have provided, you will first have to push your code/solution i.e. the content of your C:\ drive to your repository.

Unable to run C# test unit project using batch command from jenkins

I am doing automation using selenium and c#. Everything is running file when I run from visual studio but getting issue in file path then run via jenkins.
Batch command I am trying :
"nuget.exe" restore UnitTestProject1.sln
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" UnitTestProject1.sln
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\MSTest.exe" /testcontainer:UnitTestProject1\bin\Debug\UnitTestProject1.dll
Output from Jenkins :
Building in workspace C:\Users\developer\.jenkins\workspace\LinkedinAutomation\UnitTestProject1
[UnitTestProject1] $ cmd /c call C:\Users\developer\AppData\Local\Temp\jenkins934555759751738078.bat
C:\Users\developer\.jenkins\workspace\LinkedinAutomation\UnitTestProject1>"nuget.exe" restore UnitTestProject1.sln
MSBuild auto-detection: using msbuild version '15.5.180.51428' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin'.
All packages listed in packages.config are already installed.
C:\Users\developer\.jenkins\workspace\LinkedinAutomation\UnitTestProject1>"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" UnitTestProject1.sln
Microsoft (R) Build Engine version 4.6.1055.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 3/5/2018 6:38:36 PM.
Project "C:\Users\developer\.jenkins\workspace\LinkedinAutomation\UnitTestProject1\UnitTestProject1.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
Building solution configuration "Debug|Any CPU".
Project "C:\Users\developer\.jenkins\workspace\LinkedinAutomation\UnitTestProject1\UnitTestProject1.sln" (1) is building "C:\Users\developer\.jenkins\workspace\LinkedinAutomation\UnitTestProject1\UnitTestProject1\UnitTestProject1.csproj" (2) on node 1 (default targets).
Project file contains ToolsVersion="15.0". This toolset may be unknown or missing, in which case you may be able to resolve this by installing the appropriate version of MSBuild, or the build may have been forced to a particular ToolsVersion for policy reasons. Treating the project as if it had ToolsVersion="4.0". For more information, please see http://go.microsoft.com/fwlink/?LinkId=291333.
GenerateTargetFrameworkMonikerAttribute:
Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
CoreCompile:
Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.
_CopyOutOfDateSourceItemsToOutputDirectory:
Skipping target "_CopyOutOfDateSourceItemsToOutputDirectory" because all output files are up-to-date with respect to the input files.
_CopyAppConfigFile:
Skipping target "_CopyAppConfigFile" because all output files are up-to-date with respect to the input files.
CopyFilesToOutputDirectory:
UnitTestProject1 -> C:\Users\developer\.jenkins\workspace\LinkedinAutomation\UnitTestProject1\UnitTestProject1\bin\Debug\UnitTestProject1.dll
Done Building Project "C:\Users\developer\.jenkins\workspace\LinkedinAutomation\UnitTestProject1\UnitTestProject1\UnitTestProject1.csproj" (default targets).
Done Building Project "C:\Users\developer\.jenkins\workspace\LinkedinAutomation\UnitTestProject1\UnitTestProject1.sln" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:01.03
C:\Users\developer\.jenkins\workspace\LinkedinAutomation\UnitTestProject1>"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\MSTest.exe"
Microsoft (R) Test Execution Command Line Tool Version 15.0.27019.1
Copyright (c) Microsoft Corporation. All rights reserved.
Please specify tests to run, or specify the /publish switch to publish results.
For switch syntax, type "MSTest /help"
C:\Users\developer\.jenkins\workspace\LinkedinAutomation\UnitTestProject1>/testcontainer:UnitTestProject1.dll
The filename, directory name, or volume label syntax is incorrect.
C:\Users\developer\.jenkins\workspace\LinkedinAutomation\UnitTestProject1>exit 123
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
It seems everything is fine till end. It has issue in finding project dll file at end with test container.
I have the following set as a Windows Batch command:
. This is one long line that runs the individual project Test DLLs of our components. Each DLL is from a Unit Test Project.
It appears that your command line has forward slashes, and not the Windows directory separator, the backslash.
I have also found that I needed a different command line to get my tests running properly. I had to use the vstest.console.exe to run the tests.
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" Application_Tests\bin\Release\Application_Tests.dll AppLib_Tests\bin\Release\AppLib_Tests.dll
For the full command line: vstest.console.exe command line

Bitbucket pipelines .net deploy

I am trying to use new tool pipelines from bitbucket. I have multiple .NET console application (not Core app) than i want to build and download. I found this page that says that I can use mono to build my project. I use this .yml file to build it.
image: mono
pipelines:
default:
- step:
script:
- nuget restore
- MONO_IOMAP=case xbuild /t:Build /p:Configuration="Release" /p:Platform="Any CPU" Solution.sln
Build was successful but now I am stuck with downloading my app (exe with all dlls). I found here that I can use bitbucket downloads. But how to download my deploy folder? Here I found that I can zip some files and then put it to bitbucket downloads. But how I can use this with mono, and how I can zip a whole folder, and then download it? I don't mind to use something else like mono.
Mono is built on debian:wheezy, any linux commands you run in the script portion of the YML file can help you extract the file before BitBucket Pipelines pulls down the container. In the example you included there is a POST command at the end which deploys the artefact to Downloads in Bitbucket.
curl -v -u $BB_ACCESS -X POST https://api.bitbucket.org/2.0/repositories/$BITBUCKET_REPO_OWNER/$BITBUCKET_REPO_SLUG/downloads/ -F files=#aqua_lambda.zip
It explains the environment variables $BB_ACCESS further down, others are loaded in at runtime for you.
You'll need to find the file path mono compiles to and adjust the example's code to push to Bitbucket Downloads, or Amazon s3 is a good option too.
A bit late for this answer...
Firstly, use msbuild instead of xbuild as xbuild is deprecated.
Now, what you want is a successful build as well push the release to bitbucket downloads.
Here is how you do it:
1. Create an App password for the repository owner
Log in to Bitbucket as the repository owner (also the user who will upload the files) and go to Bitbucket Settings > App Passwords.
Create a new app password with write permissions to your repositories, and take note of the generated password that pops up. The name of the password is only for your reference, so use "Pipelines" or any other name you like.
You should now have two values that you will need for the next step.
<username>: Bitbucket username of the repository owner (and also the user who will upload the artifacts)
<password>: App password as generated by bitbucket
2. Create a Pipelines environment variable with the authentication token
Define a new secure environment variable in your Pipelines settings:
Parameter name: BB_AUTH_STRING
Parameter value: <username>:<password> (using the values from step 1)
You can define this environment variable either in the repository settings, or in the settings for the account that owns the repository.
The example below shows the settings for an individual account environment variable, where the repository is owned by an individual. (Note that in the case where a team owns the repository, you must configure environment variables in the team settings for them to be visible in Pipelines.)
3. Enable your Pipeline to deploy your artifacts using curl and the Bitbucket REST API
First add line to zip your release dir:
- zip -j bin/Release.zip bin/Release/
It may be possible that the pipeline bash does not have zip installed. To install zip, add the following lines to your pipeline before the above command:
- apt-get update
- apt-get -y install zip
Now finally add the curl command that uses Bitbucket REST API:
- curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=#"bin/Release.zip"
If you wish, you can remove the unneeded release zip file from the bin dir as the zip is now already in Bitbucket downloads:
- rm -f bin/Release.zip
Here is the full pipeline.yml:
image: mono
pipelines:
default:
- step:
script:
- nuget restore
- MONO_IOMAP=case msbuild /p:Configuration="Release" /p:Platform="AnyCPU" Solution.sln
- apt-get update
- apt-get -y install zip
- zip -r bin/Release.zip bin/Release/
- curl -X POST --user "${BB_AUTH_STRING}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=#"bin/Release.zip"
- rm -f bin/Release.zip
Note that your release directory may differ from the sample above

Deploy .net application using command Line

I have an .WPF application.Using XBAP project the project as web application. The solution file having 15 projects. Among 15 projects, one is root project names 'cp'. This has other project dll. i am able to build the code. My goal is that to Publish in one Location (Ex: c:\publish)in the file format of '.deploy' of all the project(Ex: sampleproject.dll.deploy). How command should i use.? I have tried following command one by one. Nothing give proper .deploy package.
R&D
msbuild cp.sln /p:DeployOnBuild=true /p:PublishProfile=Test
msbuild cp.sln /p:DeployOnBuild=true;DeployTarget=PipelinePreDeployCopyAllFilesToOneFolder;PackageTempRootDir="C:\Publish";AutoParameterizationWebConfigConnectionStrings=false
msbuild cp.sln /p:DeployOnBuild=true;DeployTarget=Package
msbuild cp.sln /p:DeployOnBuild=true /p:PublishProfile=FileSystemDebug
msbuild cp.sln /p:DeployOnBuild=true /p:PublishProfile=myprofile
msbuild cp.csproj /p:DeployOnBuild=true /p:PublishProfile=myprofile.
msbuild cp.csproj "/p:Platform=AnyCPU;Configuration=Release;PublishDestination=C:\Publish" /t:PublishToFileSystem
If you set your publish profile and publish directory is "c:\publish" you should use the following windows commands. I suppose that You are using MSbuild 14.0.
For Windows Machine
C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" /p:DeployOnBuild=true /p:PublishProfile="C:\PublishProfiles\testprofile.pubxml" "C:\Myapp\Myproject.sln"
For Azure
C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" /p:DeployOnBuild=true /p:AllowUntrustedCertificate=true /p:PublishProfile="C:\PublishProfiles\testprofile.pubxml" /p:Password=xxxxx "C:\Myapp\Myproject.sln"

Categories