Building .net framework version 4 using msbuild - asp.net

I am working on CI pipeline for a .Net framework version 4. I am using msbuild to build the project. I am new to .net so not sure how to build the project.
below are the folders and files in my project
appservices
.gitignore
.gitlab-ci.yml
errorlog.txt
appservices.sln
below is my .gitlab-ci.yml
variable:
MSBUILD_PATH: 'C:/Program Files(x86)/MSBUILD/14.0/bin/MSBuild.exe'
stages:
- Build
Code Build
tags:
- dotnet-runner
stage- Build
script:
- $MSBuild_PATH /p:configuration=Release /clp:ErrorOnly
I got below error running my build job
+ $MSBuild_PATH /p:configuration=Release /clp:ErrorOnly
+ ~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token '/p:configuration=Release' /clp:ErrorOnly

According to the docs this flag should be -p rather than /p
https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-command-line-reference?view=vs-2019

Related

Azure Pipelines Xamarin.Forms iOS build fails with error MSB4057: The target "_IsProjectRestoreSupported" does not exist in the project

We have Xamarin.Forms solution with iOS and UWP projects. We use Azure pipelines to build the iOS project. Until yesterday everything was working fine.
Now the build fails at the NuGet Restore step with the error:
##[error]The nuget command failed with exit code(1) and error(/Users/runner/work/1/s/"MyProjectName.UWP".csproj : error MSB4057: The target "_IsProjectRestoreSupported" does not exist in the project.
We can see that the problem occurs when trying to restore NuGet packages for the UWP project on the Mac OS build host.
Image: macOS-11
Workaround will be to exclude it from the solution, but we are using it for testing purposes and this is not a good option for us.
We had the same problem yesterday for our iOS (macos-11) and Android (macos-10.15) Pipelines.
The issue 21180 for mono seems to be the root cause, which is also referenced in a pull request to update the mono version for MacOs virtual environments. Regarding to this workflow test we gave msbuild a chance, and it works.
Solution:
Instead of NuGet restore we use directly MSBuild.
- task: MSBuild#1
inputs:
solution: 'App.sln'
configuration: 'Release'
msbuildArguments: /t:restore
Looking at the log file, MSBuild ignores the UWP project. That is the behavior that NuGet had with the older mono version 6.12.0.125. Ignoring the UWP-Project is no problem, because it can only be build on windows environments.
Project "/Users/runner/work/1/s/App.sln" on node 1 (Restore target(s)).
ValidateSolutionConfiguration:
Building solution configuration "Release|Any CPU".
/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/NuGet.targets(315,5): warning : Skipping restore for project '/Users/runner/work/1/s/App/App.UWP/App.UWP.csproj'. The project file may be invalid or missing targets required for restore. [/Users/runner/work/1/s/App.sln]
Some additional information:
The NuGet restore task uses msbuild to find all referenced packages. If that fails, it will use the packages.config file as fallback, the pipeline step will not fail.
Instead we got an error in the build steps for Android & iOS:
error NETSDK1004: Assets file
'/Users/runner/work/1/s/../obj/project.assets.json' not found. Run a
NuGet package restore to generate this file.
Updated Answer
This can be resolved using MSBuild task instead, as the collogues mentioned below.
However, in my case this still lead to the same error. After investigating the pipeline. The root cause has been identified:
Both in MSBuild#1 and XamariniOS#2 tasks
you should target the specific iOS Project and not the solution file, like so:
"
- task: MSBuild#1
inputs:
solution: 'PathToIosProject/myproject.iOS.csproj'
configuration: '$(BuildConfiguration)'
msbuildArguments: /t:restore
" - task: XamariniOS#2
inputs:
solutionFile: PathToIosProject/myproject.iOS.csproj'
configuration: '$(BuildConfiguration)'
packageApp: true
signingIdentity: $(APPLE_CERTIFICATE_SIGNING_IDENTITY)
Old Answer
We have managed to resolve the issue. The root cause of it seems to be an update to the mono framework in the MacOS pipeline build agent.
In order to fix it, we need a script for downloading and installing an older version of the mono framework as a first step of the build pipeline like so:
link to the pipeline tasks photo
This is the code of the bash scrip used in the task:
#!/bin/bash
set -ex
MONO_MACOS_PKG_DOWNLOAD_URL='https://download.mono-project.com/archive/6.12.0/macos-10-universal/MonoFramework-MDK-6.12.0.100.macos10.xamarin.universal.pkg'
mkdir -p /tmp/mono-install
cd /tmp/mono-install
mono --version
wget -q -O ./mono-installer.pkg "$MONO_MACOS_PKG_DOWNLOAD_URL"
sudo installer -pkg ./mono-installer.pkg -target /
mono --version
ls -alh /Library/Frameworks/Mono.framework/Versions/Current

Azure DevOps pipeline 'dotnet build' can't find project

I have a repository which has nothing on master, except the Readme and azure-pipelines.yml YAML. On the development branch (the branch I want to build and deploy and have CI on) there are three folders, MVC, Test, and Console, each containing a project (an MVC version of an ASP.NET Core MVC, .NET Core console, and Xunit test project). I want to run dotnet restore and build on the MVC project, but I get the error:
2019-02-08T15:09:20.9373945Z ##[section]Starting: CmdLine
2019-02-08T15:09:20.9468192Z ==============================================================================
2019-02-08T15:09:20.9468291Z Task : Command Line
2019-02-08T15:09:20.9468353Z Description : Run a command line script using cmd.exe on Windows and bash on macOS and Linux.
2019-02-08T15:09:20.9468441Z Version : 2.146.1
2019-02-08T15:09:20.9468490Z Author : Microsoft Corporation
2019-02-08T15:09:20.9468565Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=613735)
2019-02-08T15:09:20.9468629Z ==============================================================================
2019-02-08T15:09:22.4499876Z Generating script.
2019-02-08T15:09:22.5206191Z ##[command]"C:\windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "D:\a\_temp\21484123-df40-47c7-9383-7f526daaa124.cmd""
2019-02-08T15:09:22.8173263Z MSBUILD : error MSB1009: Project file does not exist.
2019-02-08T15:09:22.8173430Z Switch: MVC
2019-02-08T15:09:23.1247189Z Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
2019-02-08T15:09:23.1308513Z Copyright (C) Microsoft Corporation. All rights reserved.
2019-02-08T15:09:23.1308642Z
2019-02-08T15:09:23.1308714Z MSBUILD : error MSB1009: Project file does not exist.
2019-02-08T15:09:23.1308801Z Switch: MVC
2019-02-08T15:09:23.2993350Z ##[error]Cmd.exe exited with code '1'.
2019-02-08T15:09:23.3158684Z ##[section]Finishing: CmdLine
The YAML file in master is the following:
# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger:
- dev
- master
pool:
vmImage: 'vs2017-win2016'
#- task: DotNetCoreInstaller#0
# inputs:
# version: '2.2.103' # replace this value with the version that you need for your project
steps:
- script: |
dotnet restore MVC
dotnet build MVC
- task: PublishBuildArtifacts#1
- script: |
echo Add other tasks to build, test, and deploy your project.
echo See https://aka.ms/yaml
displayName: 'Run a multi-line script'
- task: PublishBuildArtifacts#1
Is there a way to access MVC for the dotnet commands?

How to specify Solution file in Azure DevOps Pipeline

I am having trouble configuring an Azure DevOps Dotnet core build process.
I have a simple dotnet core project which I am attempting to build in an Azure DevOps environment.
The project is in a subfolder within my repo, but I cannot figure out how to specify how the Pipeline should find my csproj file. The MSDN documentation suggests that you can specify it but there are no examples and all of my attempts are met with errors.
When building a pipeline with the standard dotnet CLI template, the YAML created is:
# ASP.NET Core
# Build and test ASP.NET Core web applications targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://learn.microsoft.com/vsts/pipelines/languages/dotnet-core
pool:
vmImage: 'Ubuntu 16.04'
variables:
buildConfiguration: 'Release'
steps:
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
However this is met with the error:
MSBUILD : error MSB1003: Specify a project or solution file.
The current working directory does not contain a project or solution file.
The documentation linked above suggests using a "task" based syntax rather than a script, and I assume that in the documentation the inputs are listed in the same order as the examples listed underneath.
If you use the script you specify the csproj file after the build word:
- script: dotnet build myrepo/test/test.csproj --configuration $(buildConfiguration)
The best way to use Azure DevOps Pipeline is to use tasks for the build pipeline, in the Dotnet Core yaml build task you specify the file in the inputs section:
- task: DotNetCoreCLI#2
inputs:
command: 'build'
projects: 'myrepo/test/test.csproj'

DocFx Error after installing dotnet core 2.1.300

I've create a simple console application along with a simple docfx project. When I run the DocFX command to generate the documentation I get the following metadata warning and becuasue the warning leads to the documentation not being generated.
[18-06-05 05:52:41.715]Warning:MetadataCommand.ExtractMetadataWorkspace failed with: [Failure] Msbuild failed when processing the file 'E:\Files\tmp\docx\docfx_project\src\src.csproj' with message: C:\Program Files\dotnet\sdk\2.1.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets: (198, 5): Error loading lock file 'E:\Files\tmp\docx\docfx_project\src\obj\project.assets.json' : Object reference not set to an instance of an object.
later in the output you see
[18-06-05 05:52:42.467]Warning:[MetadataCommand.ExtractMetadata]No metadata is generated for src.
Anyone else run into this problem? How can I get metadata to generate?
To recreate the project is pretty simple:
goto dotnet cli tools command line
docfx init
cd src
dotnet new console
cd ..
docfx
I have installed and using the dotnet sdk 2.1.300
With .net 2.1 there is a breaking change in the use of tools, which are now installed and used globally like this:
dotnet watch
dotnet user-secrets
dotnet sql-cache
dotnet dev-certs
The developers of docfx are currently working on a version which supports .net 2.1 (docfx v3): https://github.com/dotnet/docfx/pull/2829
Here you can see the current status of implemenation: https://github.com/dotnet/docfx/projects/1
So the answer to your question is: as of yet you can't use docfx with .net 2.1

Appveyor dotnet publish failing using net core 1.0.0

I have the current configuration for appveyor
version: 0.0.{build}
before_build:
- nuget restore mysolution.sln
- cmd: set BUILD_VERSION=%APPVEYOR_BUILD_NUMBER%
configuration: Release
build:
project: myproject.xproj
after_build:
- dotnet publish myproject --framework netcoreapp1.0 --output %APPVEYOR_BUILD_FOLDER%\out --configuration Release
- 7z a %APPVEYOR_BUILD_FOLDER%\package-net-core.zip %APPVEYOR_BUILD_FOLDER%\out\*
Until yesterday it was working fine. But for some reason after building today I see this error:
C:\projects\myproject.xproj(7,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\1.0.1\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
I'm using Visual Studio 2015, net core "version": "1.0.0-preview2-003131"
Any ideas?
Found the solution here.
After copying global.json to root it worked.

Resources