tamirisadp
tamirisadp

Reputation: 103

MSB3245: Could not resolve this reference. Could not locate the assembly

I am getting the following error message, when i build the code using the Azure DevOps. The same code, when I build locally, I am able to build it successfully.

Warning MSB3245: Could not resolve this reference. Could not locate the assembly "Azure.Core, Version=1.20.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

I am not able to figure out what am i missing here.

Following is the YAML FIle:

# 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:
- feature/bla

variables:
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

pool:
  vmImage: 'windows-latest'

steps:

- task: NuGetToolInstaller@1


- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: './src/Lidia.SSIS.ScriptUtils.sln'    
    
    
- task: VSBuild@1
  inputs:
    solution: './src/bla.sln'
    vsVersion: '16.0'
    msbuildArgs: '/p:OutDir=$(build.artifactstagingdirectory)/bla'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
    clean: true

- task: PublishBuildArtifacts@1
  displayName: 'Publish ScriptUtils project'
  inputs:
    PathtoPublish: '$(Build.ArtifactStagingDirectory)/bla'
    ArtifactName: 'bla'
    publishLocation: 'Container'

Snippet of build log:

2022-01-24T17:24:41.1372670Z ##[section]Starting: VSBuild
2022-01-24T17:24:41.1534676Z ==============================================================================
2022-01-24T17:24:41.1534981Z Task         : Visual Studio build
2022-01-24T17:24:41.1535235Z Description  : Build with MSBuild and set the Visual Studio version property
2022-01-24T17:24:41.1536444Z Version      : 1.198.1
2022-01-24T17:24:41.1537072Z Author       : Microsoft Corporation
2022-01-24T17:24:41.1537368Z Help         : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/visual-studio-build
2022-01-24T17:24:41.1537684Z ==============================================================================
2022-01-24T17:24:42.4992500Z ##[command]"D:\a\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.198.1\ps_modules\MSBuildHelpers\vswhere.exe" -version [16.0,17.0) -latest -format json
2022-01-24T17:24:42.9208406Z ##[command]"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\msbuild.exe" "D:\a\1\s\src\testest.sln" /nologo /nr:false /t:"Clean" /dl:CentralLogger,"D:\a\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.198.1\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll";"RootDetailId=10b407f2-71af-4715-8e64-1e541b1a862f|SolutionDir=D:\a\1\s\src|enableOrphanedProjectsLogs=true"*ForwardingLogger,"D:\a\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.198.1\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" /p:OutDir=D:\a\1\a/testest /p:platform="Any CPU" /p:configuration="Release" /p:VisualStudioVersion="16.0" /p:_MSDeployUserAgent="VSTS_50ac3de3-2135-4b5c-a9b3-2b73c7988867_build_319_0"
2022-01-24T17:24:43.0654724Z Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
2022-01-24T17:24:43.1337848Z Build started 1/24/2022 5:24:43 PM.
2022-01-24T17:24:43.3530655Z Project "D:\a\1\s\src\testest.sln" on node 1 (Clean target(s)).
2022-01-24T17:24:43.3539797Z ValidateSolutionConfiguration:
2022-01-24T17:24:43.3540299Z   Building solution configuration "Release|Any CPU".
2022-01-24T17:24:43.4997279Z Project "D:\a\1\s\src\testest.sln" (1) is building "D:\a\1\s\src\testest.Tests\Lidia.SSIS.Tests.csproj" (2) on node 1 (Clean target(s)).
2022-01-24T17:24:43.4997907Z CoreClean:
2022-01-24T17:24:43.4998177Z   Creating directory "obj\Release\".
2022-01-24T17:24:43.6865893Z Project "D:\a\1\s\src\testest.Tests\Lidia.SSIS.Tests.csproj" (2) is building "D:\a\1\s\src\testest\testest.csproj" (3:2) on node 1 (Clean target(s)).
2022-01-24T17:24:43.6867249Z CoreClean:
2022-01-24T17:24:43.6867911Z   Creating directory "obj\Release\".
2022-01-24T17:24:43.6906930Z Done Building Project "D:\a\1\s\src\testest\testest.csproj" (Clean target(s)).
2022-01-24T17:24:43.6908456Z Done Building Project "D:\a\1\s\src\testest.Tests\Lidia.SSIS.Tests.csproj" (Clean target(s)).
2022-01-24T17:24:43.6921849Z Done Building Project "D:\a\1\s\src\testest.sln" (Clean target(s)).
2022-01-24T17:24:43.6958975Z 
2022-01-24T17:24:43.6959730Z Build succeeded.
2022-01-24T17:24:43.6964730Z     0 Warning(s)
2022-01-24T17:24:43.6965326Z     0 Error(s)
2022-01-24T17:24:43.6966592Z 
2022-01-24T17:24:43.6967492Z Time Elapsed 00:00:00.56
2022-01-24T17:24:43.8608970Z ##[command]"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\msbuild.exe" "D:\a\1\s\src\testest.sln" /nologo /nr:false /dl:CentralLogger,"D:\a\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.198.1\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll";"RootDetailId=356c0d1e-5323-43e1-bb4e-b9c582c4652a|SolutionDir=D:\a\1\s\src|enableOrphanedProjectsLogs=true"*ForwardingLogger,"D:\a\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.198.1\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" /p:OutDir=D:\a\1\a/testest /p:platform="Any CPU" /p:configuration="Release" /p:VisualStudioVersion="16.0" /p:_MSDeployUserAgent="VSTS_50ac3de3-2135-4b5c-a9b3-2b73c7988867_build_319_0"
2022-01-24T17:24:44.0215853Z Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
2022-01-24T17:24:44.0785529Z Build started 1/24/2022 5:24:44 PM.
2022-01-24T17:24:44.2417508Z Project "D:\a\1\s\src\testest.sln" on node 1 (default targets).
2022-01-24T17:24:44.2426320Z ValidateSolutionConfiguration:
2022-01-24T17:24:44.2426747Z   Building solution configuration "Release|Any CPU".
2022-01-24T17:24:44.3935986Z Project "D:\a\1\s\src\testest.sln" (1) is building "D:\a\1\s\src\testest\testest.csproj" (2) on node 1 (default targets).
2022-01-24T17:24:44.3937769Z PrepareForBuild:
2022-01-24T17:24:44.3938123Z   Creating directory "D:\a\1\a/testest\".
2022-01-24T17:24:45.6258856Z ResolveAssemblyReferences:
2022-01-24T17:24:45.6259658Z   Primary reference "Azure.Core, Version=1.20.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8, processorArchitecture=MSIL".
2022-01-24T17:24:45.6396543Z ##[warning]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2203,5): Warning MSB3245: Could not resolve this reference. Could not locate the assembly "Azure.Core, Version=1.20.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
2022-01-24T17:24:45.6435635Z C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2203,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Azure.Core, Version=1.20.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [D:\a\1\s\src\testest\testest.csproj] 

Here is the CSPROJ snippet:

 <ItemGroup>
    <Reference Include="Azure.Core, Version=1.20.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8, processorArchitecture=MSIL">
      <HintPath>..\..\..\..\..\..\..\packages\Azure.Core.1.20.0\lib\net461\Azure.Core.dll</HintPath>
    </Reference>
    <Reference Include="Azure.Identity, Version=1.5.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8, processorArchitecture=MSIL">
      <HintPath>..\..\..\..\..\..\..\packages\Azure.Identity.1.5.0\lib\netstandard2.0\Azure.Identity.dll</HintPath>
      <Private>True</Private>
    </Reference> 

Here is the packages.config snippet:

<packages>
  <package id="Azure.Core" version="1.20.0" targetFramework="net472" />
  <package id="Azure.Identity" version="1.5.0" targetFramework="net472" />
  <package id="Azure.Storage.Blobs" version="12.10.0" targetFramework="net472" /> 

Upvotes: 4

Views: 7959

Answers (3)

Kosmo
Kosmo

Reputation: 11

In our case we had to define restoreDirectory parameter to the relative directory from the solution, so in our case: ../packages.

If no folder is specified, packages are restored into a packages/ folder alongside the selected solution, packages.config, or project.json (in this case to src/SomeDirectory/packages).

steps:
- task: NuGetCommand@2
  displayName: 'NuGet restore Tests'
  inputs:
    restoreSolution: src/SomeDirectory/SomeSolution.sln
    includeNuGetOrg: false
    restoreDirectory: ../packages

Upvotes: 0

Leo Liu
Leo Liu

Reputation: 76760

MSB3245: Could not resolve this reference. Could not locate the assembly

That's because you specify the restoreDirectory for the nuget restore task.

If you are not specifying the packages folder locally when you build the solution, you should not specify it in Azure-devops.

When you specify the restoreDirectory for the nuget restore task, the restored packages are saved in the c:\packages folder, however, the referenced path for the packages in the project are still for the old path.

That is the reason why you get the error "Could not locate the assembly".

Upvotes: 3

JukkaK
JukkaK

Reputation: 1175

You should not use paths that reference drives in azure pipelines tasks, as you don't have access to directories outside the scope of the pipeline agent, so in this case your nuget restore task does not work. Use predefined variables (https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml) when referencing, like:

- task: VSBuild@1
  inputs:
    solution: '$(Build.SourcesDirectory)/src/bla.sln'

Not sure why the restore task has a restoredirectory specified. If you need to use a specific directory, again, use predefined build or agent variables. Generally speaking though, the packages should be restored and referenced without needing to specify a restoredirectory: https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/package/nuget?view=azure-devops#examples

Upvotes: 1

Related Questions