Summary
I'm using a 9.2.0 Gitlab's CI multirunner on a Windows Server 2016. On a step where I publish ASP.NET project through MSBUILD I've got an authentication error ERROR_USER_UNAUTHORIZED from IIS. But when I use a CMD window on a build machine there I run the same command for publish - everything is published. Doesn't matter if I used a SYSTEM or an ADMINISTRATOR account.
Steps to reproduce
Setup IIS publish.
Setup Gitlab's build agent.
Create the Gitlab's YAML build script (see below).
Run the build.
Actual behavior
On a publish step I've got the ERROR_USER_UNAUTHORIZED error.
Expected behavior
On a publish step I've got my ASP.NET published to a server.
Relevant logs and/or screenshots
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0\Web\Microsoft.Web.Publishing.targets(4292,5): msdeploy error ERROR_USER_UNAUTHORIZED: Не удалось выполнить задачу Web Deploy. (Выполнено подключение к удаленному компьютеру ("192.168.1.66") с использованием службы веб-управления, но не удалось авторизовать. Убедитесь, что вы используете правильные имя пользователя и пароль, что существует сайт, к которому выполняется подключение, и что учетные данные представляют пользователя, у которого есть разрешения на доступ к сайту. Дополнительные сведения: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_USER_UNAUTHORIZED.) [C:\Gitlab_Build_Agents\1\builds\2378ccf8\0\rushydro\aisa\Sources\Mvc\Mvc.csproj]
Environment description
I'm using a shared Runner (gitlab-ci-multi-runner-windows-386, version 9.2.0) on a Windows 2016. MSBUILD is a part of a Microsoft Visual Studio 2017.
YAML script
variables:
solution: Sources\Faso.sln
msbuild: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe
nunit: C:\NUnit\NUnit.Framework-3.7.0\bin\net-4.5\nunitlite-runner.exe
nuget: C:\NuGet\nuget.exe
before_script:
- echo Setting encoding...
- echo %solution%
- echo Restoring NuGet packages...
- '"%nuget%" restore "%solution%"'
stages:
- build-test
- deploy-5023
build-test:
stage: build-test
script:
- chcp 65001
- echo Building...
- '"%msbuild%" "%solution%" /t:Build /p:Configuration=Release /p:TargetFramework=v4.5.2'
- echo Testing...
- dir /s /b *.Tests.dll | findstr /r Tests\\*\\bin\\ > testcontainers.txt
- 'for /f %%f in (testcontainers.txt) do "%nunit%" "%%f"'
except:
- tags
deploy-5023:
stage: deploy-5023
script:
- chcp 65001
- echo Deploying...
- '"%msbuild%" "%solution%" /p:DeployOnBuild=True /p:DeployTarget=MSDeployPublish /p:MsDeployServiceUrl=https://192.168.1.66:8172/msdeploy.axd /p:username=user /p:password=password /p:Configuration=Release /p:TargetFramework=v4.5.2 /p:AllowUntrustedCertificate=True /p:DeployIisAppPath=Faso /p:MSDeployPublishMethod=WMSVC /p:SkipExtraFilesOnServer=True /p:ExcludeFilesFromDeployment="Web.config;ConnectionStrings.config;system.config"'
when: manual
except:
- tags
artifacts:
expire_in: 1 week
paths:
- Sources\Mvc\App_Data\
- Sources\Mvc\bin\
- Sources\Mvc\Content\
- Sources\Mvc\favicon.ico
- Sources\Mvc\Global.asax
- Sources\Mvc\Web.config
Solved by changing the arguments' order and format for MSBUILD.
- '"%msbuild%" "%solution%" /p:DeployOnBuild=True;Username=username;Password=password;DeployTarget=MSDeployPublish;MsDeployServiceUrl=https://192.168.1.66:8172/msdeploy.axd;Configuration=Release;TargetFramework=v4.5.2;AllowUntrustedCertificate=True;DeployIisAppPath=Faso;MSDeployPublishMethod=WMSVC;SkipExtraFilesOnServer=True;ExcludeFilesFromDeployment="Web.config;ConnectionStrings.config;system.config"'
Related
I trying to integrate my Solution based on .net6 with SonarCloud and Github actions.The problem is that the action build failed on the sonar scanner end.I tried to change working dirs but with the same effect.The project is public HERE
The SonarScanner for MSBuild integration failed: SonarCloud was unable to collect the required information about your projects.
Possible causes:
The project has not been built - the project must be built in between the begin and end steps
An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0.25420.1 and higher are supported.
The begin, build and end steps have not all been launched from the same folder
None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln) SonarScanner for MSBuild 5.7.2 Using
the .NET Core version of the Scanner for MSBuild Post-processing
started. 10:38:06.016 Generation of the sonar-properties file failed.
Unable to complete the analysis. 10:38:06.024 Post-processing failed.
Exit code: 1 Error: Process completed with exit code 1.
name: build-all
# Controls when the action will run.
on:
push:
branches:
- main
env:
DOTNET_VERSION: 6.0.x
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build-windows:
# The type of runner that the job will run on
runs-on: windows-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout#v2
with:
# Disabling shallow clone is recommended for improving relevancy of reporting
fetch-depth: 0
- uses: actions/setup-dotnet#v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- uses: microsoft/setup-msbuild#v1
- uses: actions/setup-java#v2
with:
distribution: 'adopt'
java-version: '11'
- name: Restore NuGet packages
run: |
cd App
nuget restore App.sln
- name: Begin Sonar scan
run: |
cd App
dotnet tool install --global dotnet-sonarscanner
dotnet sonarscanner begin /o:vladimirpetukhov /k:vladimirpetukhov_Musement_CLI /d:sonar.login=${{ secrets.SONAR_TOKEN }} /d:sonar.host.url=https://sonarcloud.io
- name: Build Api
run: |
cd ./App/App.API
dotnet build App.API.csproj --no-restore
# dotnet test App.API.csproj --no-build --no-restore --verbosity normal -p:CollectCoverage=true -p:CoverletOutputFormat=opencover
- name: Build Main
run: |
cd ./App/App.Main
dotnet build App.Main.csproj --no-restore
# dotnet test App.Main.csproj --no-build --no-restore --verbosity normal -p:CollectCoverage=true -p:CoverletOutputFormat=opencover
- name: End Sonar scan
run: |
cd App
dotnet sonarscanner end /d:sonar.login=${{ secrets.SONAR_TOKEN }}
I've created a simple ASP.NET CORE 6 Web API. I then pushed it to Github. When I try to create a pipeline in Azure Devops, I'm getting the error.
C:\Program Files\dotnet\sdk\5.0.403\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET
.TargetFrameworkInference.targets(141,5): error NETSDK1045: The current .NET SDK does not support
targeting .NET 6.0. Either target .NET 5.0 or lower, or use a version of the .NET SDK that supports
.NET 6.0.
I've just downloaded VS 2022 community edition. I've installed .Net SDK 6.
Here's my csproj file
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
</Project>
I chose what Azure devops suggested, so this is my yml file
# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package
/p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true
/p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
I've followed what's said in this documentation, but it's not working. The build is still failing like this
[![enter image description here][2]][2]
Thanks for helping
After reading this 2 links, it there were 2 issues with the template from Azure devops.
the restore packages kept on looking for SDK 5. So this task fixed the issue. I've to include a step that mentions SDK 6. https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/package/nuget?view=azure-devops
also it kept on targeting Visual Studio 2019, which doesn't support .NET 6.0.x. Therefore, instead of vmImage: 'windows-latest', using vmImage: 'windows-2022' allow the build to succeed https://github.com/dotnet/core/issues/6907.
I ended up using the classic template so that I can understand better how the pipeline works. 1) Either using ubuntu-latest or windows-2022. 2) add a step for the version of SDK.
I chose what Azure devops suggested, so this is my yml file
Unfortunately it's easy to confuse things, since Microsoft's naming is anything but consistent.
You need to use .NET Core guide for this: Build, test, and deploy .NET Core apps
To save you time, here is a simple YAML pipeline to build ASP.NET Core applications:
trigger:
branches:
include:
- master
# Setup pipeline-level variables to keep things DRY
variables:
configuration: Release
projects: '**/*.csproj'
publish_dir: $(Build.ArtifactStagingDirectory)
vm_image: ubuntu-latest
stages:
- stage: Build
jobs:
- job: dotnet
displayName: .NET
pool:
vmImage: $(vm_image)
# Run builds in latest .NET 6 SDK container (Debian 11)
# This simplifies things and allows to easily target different SDKs:
# https://hub.docker.com/_/microsoft-dotnet-sdk
container: mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim
workspace:
clean: all
# Build tasks a separated (restore/build/test/publish)
# to make it easier to catch/debug issues
steps:
- task: DotNetCoreCLI#2
displayName: .NET | Restore [$(configuration)]
inputs:
command: restore
projects: $(projects)
- task: DotNetCoreCLI#2
displayName: .NET | Build [$(configuration)]
inputs:
command: build
projects: $(projects)
arguments: --configuration $(configuration) --no-restore
- task: DotNetCoreCLI#2
displayName: .NET | Test [$(configuration)]
inputs:
command: test
projects: $(projects)
publishTestResults: true
arguments: --configuration $(configuration) --no-restore --no-build
- task: DotNetCoreCLI#2
displayName: .NET | Publish [$(configuration)]
inputs:
command: publish
publishWebProjects: true
zipAfterPublish: true
modifyOutputPath: true
arguments: --configuration $(configuration) --output $(publish_dir) --no-restore --no-build
# Publish zipped build results so they can be downloaded from the pipeline UI
- publish: $(publish_dir)
displayName: Artifact | Publish
artifact: $(Build.DefinitionName)
I am trying to build automatically a golang project in a windows environment with travis and to package the .exe making use of msbuild and wix.
The very same configuration works with Github actions and therefore I believe that both the .wixproj and the wxs are correct and there is some issue with the configuration of msbuild in the travis installation, but I have no more clues.
Possibly the msbuild installed by travis does not include the required wix toolset, I tried to install them, however while creating the package the error persist
The error
C:\Users\travis\gopath\src\github.com\gallo-cedrone\nri-elasticsearch\pkg\windows\nri-amd64-installer\nri-installer.wixproj" (default target) (1) ->
C:\Users\travis\gopath\src\github.com\gallo-cedrone\nri-elasticsearch\pkg\windows\nri-amd64-installer\nri-installer.wixproj(34,5):
error MSB4019: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\WiX\v3.x\Wix.targets" was not found.
Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
.travis
...
- os: windows
env:
- MSBUILD_PATH="c:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin"
before_script:
- powershell Install-WindowsFeature Net-Framework-Core
- cinst -y wixtoolset
script:
- export PATH=$MSBUILD_PATH:$PATH
- go test ./src/
- go build -v -o ./target/bin/windows_amd64/nri-elasticsearch.exe ./src/
- msbuild.exe -version
- cd ./pkg/windows/nri-amd64-installer/ ; pwd ; env ; msbuild.exe ./nri-installer.wixproj
...
travis job logs
I found a solution thanks to enter link description here
Basically I was installing the wixtools, however the installation folder was not the expected one by vs2017.
It can be fixed simply by changing:
<Import Project="$(WixTargetsPath)" />
with:
<Import Project="$(WixTargetsPath)" Condition=" '$(WixTargetsPath)' != '' " />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets" Condition=" '$(WixTargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets') " />
and removing the WixTargetsPath clouses contitions.
I need help to setup my azure-pipelines.yml build file because I cannot find any good tutorial, sample or other kind of help anywhere.
I follow this tutorial by Microsoft https://learn.microsoft.com/en-us/azure/devops/pipelines/languages/dotnet-core?view=azure-devops but despite all information they give I still get errors.
azure-pipelines.yml
# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
pool:
vmImage: 'Ubuntu-16.04'
variables:
buildConfiguration: 'Release'
steps:
# - script: dotnet build --configuration $(buildConfiguration)
# displayName: 'dotnet build $(buildConfiguration)'
- task: DotNetCoreInstaller#0
inputs:
version: '2.2.202' # replace this value with the version that you need for your project
- script: dotnet restore
- task: DotNetCoreCLI#2
displayName: Build
inputs:
command: build
projects: '**/*.csproj'
arguments: '--configuration Release' # Update this to match your need
# do this after you've built your app, near the end of your pipeline in most cases
# for example, you do this before you deploy to an Azure web app on Windows
- task: DotNetCoreCLI#2
inputs:
command: publish
publishWebProjects: True
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True
- task: PublishBuildArtifacts#1
inputs:
ArtifactName: 'drop'
Log
##[section]Starting: DotNetCoreCLI
==============================================================================
Task : .NET Core
Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command. For package commands, supports NuGet.org and authenticated feeds like Package Management and MyGet.
Version : 2.150.1
Author : Microsoft Corporation
Help : [More Information](https://go.microsoft.com/fwlink/?linkid=832194)
==============================================================================
##[error]No web project was found in the repository. Web projects are identified by presence of either a web.config file or wwwroot folder in the directory.
##[error]Project file(s) matching the specified pattern were not found.
##[section]Finishing: DotNetCoreCLI
Why these error and what am I doing wrong?
Additional information
- I can build and publish from Visual Studio to my Azure web app. My API is working. I just cannot do it as part of CI / CD.
- I don't understand this error because I don't understand why the DotNetCore are requesting a web.config.
It only worked for me when I gave it the path to my Web API (set **/*WebApi.csproj to your own location).
But just as importantly, I had to assure the build agent it was NOT a web project by setting publishWebProjects to false.
- task: DotNetCoreCLI#2
displayName: '📗📗📗 Publish 📗📗📗'
inputs:
command: publish
projects: '**/*WebApi.csproj'
publishWebProjects: False
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True
Q: Are emojis necessary in the publish definition?
A: Yes, emojis are necessary. (Actually, no. But it would be less silly than having to set publishWebProjects to false.)
I am getting this MsBuild error when trying to build my Universal Windows Platform (UWP) application with AppVeyor:
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(2048,5): error MSB3774: Could not find SDK "Microsoft.AdMediator.Universal, Version=1.0". [C:\projects\santasegameengine\Source\UI\Santase.UI.WindowsUniversal\Santase.UI.WindowsUniversal.csproj]
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(2048,5): error MSB3774: Could not find SDK "Microsoft.Advertising.Xaml, Version=10.0". [C:\projects\santasegameengine\Source\UI\Santase.UI.WindowsUniversal\Santase.UI.WindowsUniversal.csproj]
Here is the full build log: https://ci.appveyor.com/project/NikolayIT/santasegameengine/build/1.0.252
And here is the source code of the app in GitHub: https://github.com/NikolayIT/SantaseGameEngine/tree/master/Source/UI/Santase.UI.WindowsUniversal
How can I fix such an error?
Adding this as PS (PowerShell) script (as before build script) fixed the problem for me:
Here is the script:
Write-Host "Installing Microsoft Universal Ad Client SDK..."
$msiPath = "$($env:USERPROFILE)\AdMediator.msi"
(New-Object Net.WebClient).DownloadFile('https://visualstudiogallery.msdn.microsoft.com/401703a0-263e-4949-8f0f-738305d6ef4b/file/146057/6/AdMediator.msi', $msiPath)
cmd /c start /wait msiexec /i $msiPath /quiet
Write-Host "Installed" -ForegroundColor green
And the result: