'Could not be resolved because it has an indirect dependency on the assembly - Azure DevOps Build Pipeline
I have two projects. Project 1 and Project 2. Project 1 refers to Project 2 in its csproj file. I have recently upgraded the Project 2 to a higher version of the .NET. When I did the same for Project 1 and ran my CI Pipeline, I have been getting quite a lot of errors, mostly like below. When I run the CI pipeline for Proj 2 seperately, it is building successfully.
I checked all possible places to see if I have any old references, but I am unable to find where exactly is the problem. Appreciate your help here.
Done Building Project "D:\a\1\s\dia-praj2\src\Proj-2\Proj-2.csproj" (default targets).
##[warning]D:\a\1\s\dia-proj1\proj1.metaproj(0,0): Warning MSB3274: The primary reference "D:\a\1\s\dia-praj2\src\Proj-2\bin\Release\Proj-2.dll" could not be resolved because it was built against the ".NETFramework,Version=v4.7.2"
##[warning]D:\a\1\s\dia-proj1\proj1.metaproj(0,0): Warning MSB3275: The primary reference "D:\a\1\s\dia-praj2\src\Proj-2\bin\Release\Proj-2.dll" could not be resolved because it has an indirect dependency on the assembly "CsvHelper, Version=27.0.0.0, Culture=neutral, PublicKeyToken=8c4959082be5c823" which was built against the ".NETFramework,Version=v4.7" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.5".
##[warning]D:\a\1\s\dia-proj1\proj1.metaproj(0,0): Warning MSB3275: The primary reference "D:\a\1\s\dia-praj2\src\Proj-2\bin\Release\Proj-2.dll" could not be resolved because it has an indirect dependency on the assembly "Azure.Core, Version=1.22.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8" which was built against the ".NETFramework,Version=v4.6.1" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.5".
##[warning]D:\a\1\s\dia-proj1\proj1.metaproj(0,0): Warning MSB3275: The primary reference "D:\a\1\s\dia-praj2\src\Proj-2\bin\Release\Proj-2.dll" could not be resolved because it has an indirect dependency on the assembly "Microsoft.Bcl.AsyncInterfaces, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" which was built against the ".NETFramework,Version=v4.6.1" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.5".
My Build Pipeline
a# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4
pool:
vmImage: 'windows-latest'
variables:
solution: '**/Proj-1.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
name: $(Build.DefinitionName)_$(SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)
resources:
repositories:
- repository: Proj-2
name: Proj-2
type: git
ref: feature/Proj-2
# this is being defined in app-ci pipeline
steps:
- script: echo '$(Build.BuildNumber)'
displayName: "echo build number"
- checkout: Proj-2
displayName: 'checkout Proj-2'
- checkout: self
displayName: 'checkout Proj-1'
- task: NuGetToolInstaller@1
displayName: Install Nuget Package Manager
- task: NuGetCommand@2
displayName: Restore Nuget packages
inputs:
command: 'restore'
restoreSolution: '$(solution)'
restoreDirectory: 'c:\packages'
- task: VSBuild@1
displayName: Build dia-ui solution
inputs:
solution: '$(solution)'
vsVersion: '16.0'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
clean: true
- task: CopyFiles@2
displayName: Copy everything to the Binaries dir
inputs:
Contents: '**/Prj1/abc/**'
TargetFolder: $(Build.BinariesDirectory)
- task: ArchiveFiles@2
displayName: Zip the binaries dir into a file called 'drop.zip'
inputs:
rootFolderOrFile: '$(Build.BinariesDirectory)/Prj1/abc/'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/drop.zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts@1
displayName: Publish 'drop.zip' as an artifact
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)/drop.zip'
ArtifactName: 'drop'
Solution 1:[1]
The dependencies of your project do not match the .NET version your project is on now. I had the same issue and reinstalled the packages using the method mentioned here. In short: in the package manager console run
update-package <package name> -reinstall
Do this for all packages installed in the project where you changed the .NET version.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MarTim |
