DevOps CI pipe is failing claiming Microsoft.Bcl.Build - visual-studio

I have a project that pulls from both public and private NuGet repositories. This works. But what doesn't seem to work is that the build on CI fails because of Microsoft.Bcl.Build, which should have gotten downloaded from the Nuget Restore Step
trigger:
- master
pool:
vmImage: 'windows-2019'
demands:
- msbuild
- visualstudio
- VSTest
- DotNetFramework
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#0
displayName: 'Use NuGet 4.4.1'
inputs:
versionSpec: 4.4.1
- task: NuGetCommand#2
displayName: 'NuGet restore'
inputs:
restoreSolution: '$(Parameters.solution)'
feedsToUse: config
nugetConfigPath: .nuget/NuGet.Config
- task: VSBuild#1
displayName: 'Run Build on solution.'
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)" /p:BclBuildImported=Ignore'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
logFileVerbosity: 'diagnostic'
In the sample above, I have tried both using and removing /p:BclBuildImported=Ignore'.
The library I am using has BCL ref in it, so I cannot remove that dependancy. And this code falls apart when I switch it to core.
Everything does work when I build it in Visual Studio 2019 Ent, and Pro, just refuses to build on MS DevOps, on the Hosted 2017 platform.
Tried fixes, and comment/discussion follow-up since initial post:
Multiple pools have been tried, all failing.
This does build in VS 2017 & 2019 on pro and enterprise on various desktops.
The error is This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets. even though all packages are being installed, and the Nuget download shows no errors or skips.
The following fixes have not worked:
How to bypass Microsoft.Bcl.Build warning
What does the Microsoft.Bcl.Build NuGet package do?

Have you tried MS DevOps, on the Hosted 2019 platform, instead of using a 2017 Host?
Hosted Windows 2019 with VS2019

I ended up removing all BCL dependencies and built a lot of workarounds. This was no minor change. Unfortunately, as this is 2 years ago, I don't have the details of what I did back then.

Related

Ignore Project on DevOps Pipeline

I'm having trouble ignoring a specific project in my DevOps Pipeline. I have a WPF project in the same solution as my .Net MAUI project and I have a Pipeline for the WPF Solution that works but the .Net MAUI one fails on Nuget Restore because it's Using MAUI and a macOS-12 Image.
- task: DotNetCoreCLI#2
displayName: 'Nuget Restore'
inputs:
command: 'restore'
projects: '**/*.csproj
!**/Portal.Desktop.csproj' # This is supposed to ignore the WPF App
feedsToUse: 'config'
nugetConfigPath: 'nuget.config'
I get a pattern matching error though so apparently that's not right
The Error
Nuget Restore
View raw log
Starting: Nuget Restore
Task : .NET Core
Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version : 2.210.0
Author : Microsoft Corporation
Help : docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
##[error]No files matched the search pattern.
Finishing: Nuget Restore
I can reproduce the match error via using the below YAML:
trigger:
- none
pool:
vmImage: 'windows-latest'
steps:
- task: DotNetCoreCLI#2
displayName: 'Nuget Restore'
inputs:
command: 'restore'
projects: '
**/*.csproj
!**/TestResultsTests.csproj'
feedsToUse: 'select'
vstsFeed: '1f64a82f-77ad-4770-a098-772faae01ed1'
The error disappear after change my YAML to this:
trigger:
- none
pool:
vmImage: 'windows-latest'
steps:
- task: DotNetCoreCLI#2
displayName: 'Nuget Restore'
inputs:
command: 'restore'
projects: | #Here is where I change.
**/*.csproj
!**/TestResultsTests.csproj
feedsToUse: 'select'
vstsFeed: '1f64a82f-77ad-4770-a098-772faae01ed1'
So the issue should comes from your YAML definition.
This is my repository structure:

Azure Pipelines VisualStudioBuild task ignoring AssemblyInfo.cs

This is being built in an on-prem build agent running version 2.200.2. I've tried using VS 2017-2022 (15.0, 16.0, 17.0).
When I build my code locally, it properly parses the AssemblyInfo.cs files and applies the versioning so that when I check the details in Windows properties, it lists the version set in AssemblyFileVersion (I'm also setting AssemblyVersion and AssemblyInformationalVersion for good measure). For some reason, however, when I run the following tasks, all generated dlls and exes come out with a version of 0.0.0.0 instead of what is listed in the AssemblyInfo.cs. $(RVersion) is defaulted to 1.0.23.0 and I've validated that the AssemblyInfo.cs files are properly being updated. The value currently listed in the AssemblyInfo is 1.0.13.0, so even if it wasn't being set, it's still being ignored. Any help in figuring out why the files are being generated with 0.0.0.0 would be appreciated.
- task: Assembly-Info-NetFramework#3
inputs:
Path: '$(Build.SourcesDirectory)'
FileNames: |
**\AssemblyInfo.cs
InsertAttributes: true
VersionNumber: '$(RVersion)'
FileVersionNumber: '$(RVersion)'
InformationalVersion: '$(RVersion)'
Configuration: $(buildConfiguration)
- task: VSBuild#1 displayName: 'Build .NET Solution'
inputs:
solution: '$(solution)'
vsVersion: '17.0'
configuration: 'Release'
platform: $(buildPlatform)
msbuildArgs: '/p:SkipInvalidConfigurations=true /p:OutDir=$(Build.BinariesDirectory)'
clean: true

How to Specify .NET Framework Version in YAML Pipeline?

I'm extremely new to YAML--I'm trying to update a plug-in library using the published artifact DLL from build B (see YAML below) however I keep receiving the following error:
How can I specify the .NET Framework in the YAML so that it is not trying to use an old version? I need it to use 4.6.2. I've browsed every Microsoft Doc and found that you can specify it running tests but have had zero luck trying to find how to set it for a build.
Just to clarify, the YAML below successfully runs and I can download the DLL but upon updating the plug-in registration it will result in the error.
'''
trigger: none
pool:
vmImage: 'windows-latest'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: 'A/A.sln'
#Build the solutions
- task: VSBuild#1
displayName: 'Build A Library'
inputs:
solution: 'A/A.sln'
msbuildArgs: '/p:DeployOnBuild=true
/p:WebPublishMethod=Package
/p:PackageAsSingleFile=true
/p:SkipInvalidConfigurations=true
/p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip"
/p:DeployIisAppPath="Default Web Site"'
platform: 'Any CPU'
configuration: 'Release'
- task: VSBuild#1
displayName: 'Build B Library'
inputs:
solution: 'B/B/B.sln'
msbuildArgs: '/p:DeployOnBuild=true
/p:WebPublishMethod=Package
/p:PackageAsSingleFile=true
/p:SkipInvalidConfigurations=true
/p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip"
/p:DeployIisAppPath="Default Web Site"'
platform: 'Any CPU'
configuration: 'Release'
- publish: $(System.DefaultWorkingDirectory)/B/B/B/bin/Release/B.dll
artifact: BDll
'''
From the linked doc in the issue, the cause of the issue is that In the .NET Framework version 3.5 and earlier versions, if you loaded an assembly from a remote location, the assembly would run partially trusted with a grant set that depended on the zone in which it was loaded. If you try to run that assembly in the .NET Framework version 4 and later versions, an exception is thrown.
You can add this line in your config file:
<configuration> <runtime> <loadFromRemoteSources enabled="true"/> </runtime> </configuration>
If you want to target .NET Framework 4.6.2, you can add this line in the msbuildArgs of YMAL:
/p:TargetFrameworkVersion="v4.6.2"
If you don't add this line, it will use the default old .NET Framework when build.

What commands are behind the Visual Studio Pack command?

I'm trying to configure a GitHub workflow that builds my multi-target NuGet package (to be used with Xamarin.Forms) and pushes this package to GitHub and Nuget. I discussed the issue here, and it all seems to boil down to the following:
I cannot use dotnet pack in my workflow, it results in the following error:
C:\Users\user\.nuget\packages\msbuild.sdk.extras\2.1.2\Build\Workarounds.targets(27,5): error : If you are building projects that require targets from full MSBuild or MSBuildFrameworkToolsPath, you need to use desktop msbuild ('msbuild.exe') instead of 'dotnet build' or 'dotnet msbuild' [C:\path\to.csproj]
When I use MSBuild (either manually on my computer, or through the workflow), only the UWP declarations are available, and for all target platforms (Android, iOS, UWP).
When I right-click the class library project and click the Pack command, the resulting package works as expected. All platforms can call the platform-specific declarations.
Question:
Simple, what commands are behind the [Right-click csproj-file] → Pack? I want to try and run these commands manually to figure out what's going on...
Information:
msbuild version on my pc: 16.7.0.37604 (located at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin)
msbuild version on GitHub CI: 16.7.0+b89cb5fde
dotnet version on GitHub CI: 3.1.301
Apparently there is a bug in the MSBuild CLI.
When using the following command:
msbuild /t:Pack /p:Configuration=Debug Library/Company.Xamarin.Alert/Company.Xamarin.Alert.csproj
The produced nupkg can be installed in each project of a Xamarin.Forms application, and platform-specific code can be called.
However, when running the same command with the p:OutputPath parameter specified:
msbuild /t:Pack /p:Configuration=Debug /p:OutputPath=../.. Library/Company.Xamarin.Alert/Company.Xamarin.Alert.csproj
The resulting nupkg only contains the definitions for UWP.
I've filed a bug for this here.
My final workflow looks like this:
name: .NET Core
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout#v2
- name: Setup .NET Core
uses: actions/setup-dotnet#v1.5.0
with:
dotnet-version: 3.1.301
# Authenticates packages to push to GPR
source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
env:
NUGET_AUTH_TOKEN: '%NUGET_AUTH_TOKEN%'
- name: Setup MSBuild
uses: microsoft/setup-msbuild#v1.0.1
- name: Install dependencies
run: msbuild /t:Restore
env:
NUGET_AUTH_TOKEN: ${{ github.token }}
- name: Build
run: msbuild /t:Pack /p:Configuration=Debug Library/MintPlayer.MVVM/MintPlayer.MVVM.csproj
- name: PushNuget
run: dotnet nuget push "**/*.nupkg" --source https://api.nuget.org/v3/index.json --api-key ${{ secrets.PUBLISH_TO_NUGET_ORG }} --skip-duplicate
- name: PushGithub
run: nuget.exe push "**/*.nupkg" -NoSymbols -SkipDuplicate
env:
NUGET_AUTH_TOKEN: ${{ github.token }}

Can't build Xamarin Android project in Azure Pipelines

I'm trying to create a basic build pipeline in Azure DevOps which builds a Visual Studio solution that includes .NET Core / .NET Standard projects and a Xamarin.Android project. The solution builds locally in VS 2019 with no issues, but always fails on the build agent with these build errors:
Error APT2260: resource style/Theme.AppCompat.Light.Dialog (aka com.companyname.obrien.connect.forms:style/Theme.AppCompat.Light.Dialog) not found.
Source\Obrien.Connect.Forms.Android\Resources\values\styles.xml(4,0): Error APT2260: style attribute 'attr/colorAccent (aka com.companyname.obrien.connect.forms:attr/colorAccent)' not found.
Error APT2260: resource style/Theme.AppCompat.Light.DarkActionBar (aka com.companyname.obrien.connect.forms:style/Theme.AppCompat.Light.DarkActionBar) not found.
Source\Obrien.Connect.Forms.Android\Resources\values\styles.xml(2,0): Error APT2260: style attribute 'attr/windowNoTitle (aka com.companyname.obrien.connect.forms:attr/windowNoTitle)' not found.
Source\Obrien.Connect.Forms.Android\Resources\values\styles.xml(2,0): Error APT2260: style attribute 'attr/windowActionBar (aka com.companyname.obrien.connect.forms:attr/windowActionBar)' not found.
Source\Obrien.Connect.Forms.Android\Resources\values\styles.xml(2,0): Error APT2260: style attribute 'attr/colorPrimary (aka com.companyname.obrien.connect.forms:attr/colorPrimary)' not found.
Source\Obrien.Connect.Forms.Android\Resources\values\styles.xml(2,0): Error APT2260: style attribute 'attr/colorPrimaryDark (aka com.companyname.obrien.connect.forms:attr/colorPrimaryDark)' not found.
Source\Obrien.Connect.Forms.Android\Resources\values\styles.xml(3,0): Error APT2260: style attribute 'attr/colorAccent (aka com.companyname.obrien.connect.forms:attr/colorAccent)' not found.
Source\Obrien.Connect.Forms.Android\Resources\values\styles.xml(4,0): Error APT2260: style attribute 'attr/windowActionModeOverlay (aka com.companyname.obrien.connect.forms:attr/windowActionModeOverlay)' not found.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Aapt2.targets(155,3): Error APT2260: resource style/TextAppearance.AppCompat.Button (aka com.companyname.obrien.connect.forms:style/TextAppearance.AppCompat.Button) not foun
This is the YAML for the pipeline:
trigger:
- develop
- feature/*
pool:
vmImage: 'windows-2019'
variables:
- group: 'ci-build'
steps:
- task: NuGetToolInstaller#1
displayName: 'Install NuGet 5.4.0'
inputs:
versionSpec: '5.4.0'
- task: DotNetCoreCLI#2
displayName: 'Restore .NET Packages'
inputs:
command: restore
projects: '**/OBrien.Connect.Forms*/*.csproj'
verbosityRestore: minimal
- task: NuGetCommand#2
displayName: 'Restore Android Packages'
inputs:
command: 'restore'
restoreSolution: '**/OBrien.Connect.Forms.sln'
- task: VSBuild#1
displayName: 'Build Solution'
inputs:
solution: '**/$(solutionName)'
vsVersion: '16.0'
configuration: '$(buildConfiguration)'
I needed to use dotnet restore on the projects in the solution first, so that I could build them in the subsequent VSBuild task, that works fine. However, this doesn't restore any packages needed by the Xamarin.Android project as that is based on Mono and is ignored by the first restore.
That's why I added the second NuGet restore on the entire solution, but this never does anything - no errors, just this output:
##[section]Starting: Restore Android Packages
==============================================================================
Task : NuGet
Description : Restore, pack, or push NuGet packages, or run a NuGet command. Supports NuGet.org and authenticated feeds like Azure Artifacts and MyGet. Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.
Version : 2.161.1
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/package/nuget
==============================================================================
SYSTEMVSSCONNECTION exists true
SYSTEMVSSCONNECTION exists true
[command]C:\windows\system32\chcp.com 65001
Active code page: 65001
Detected NuGet version 5.4.0.6315 / 5.4.0+d790b66be476cd901a56bd46ada037162097ee21.d790b66be476cd901a56bd46ada037162097ee21
SYSTEMVSSCONNECTION exists true
Saving NuGet.config to a temporary config file.
[command]C:\hostedtoolcache\windows\NuGet\5.4.0\x64\nuget.exe sources Add -NonInteractive -Name NuGetOrg -Source https://api.nuget.org/v3/index.json -ConfigFile D:\a\1\Nuget\tempNuGet_552.config
Package source with Name: NuGetOrg added successfully.
##[section]Finishing: Restore Android Packages
I've tried using the XamarinAndroid#1 build task instead of building the whole solution, but it has exactly the same build errors.
I found a good solution from a colleague who had exactly the same problem, which is to trigger the Restore target from the VSBuild task, instead of doing a NuGet restore / dotnet restore, here's the YAML:
- task: VSBuild#1
displayName: 'Restore Packages'
inputs:
solution: '**/$(solutionName)'
configuration: '$(buildConfiguration)'
vsVersion: '16.0'
msbuildArgs: '/t:Restore'
This works perfectly for building the entire solution.

Resources