DEV Community

loading...
Cover image for [Solution] MSBUILD Could not locate assembly

[Solution] MSBUILD Could not locate assembly

Gabriel Barcelos | C#, AspNetCore, ReactJS
Sou desenvolvedor "fullStack" e empresário. Através da programação é possível resolver #problemas! A resolução de problemas é a base de qualquer #negócio.
・2 min read

MSBuild is a platform for building applications. This engine, which is also known as MSBuild, provides an XML schema for a project file that controls how the build platform processes and builds software.

Scenario:

I've a C# Windows Forms project .csproj that references some common dll´s.
These dll´s are coming from a folder outside project folder.
These dll´s are referenced at design time, from GAC (global assembly cache).

Problem:

When I´m building the project, inside a remote server, these dll´s should be searchable from another path.
Otherwise, I´ll receive the error below:

[warning]C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2084,5): Warning MSB3245: Could not resolve this reference. Could not locate the assembly "DevExpress.Charts.v20.1.Core". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

Solution:

  1. Open .csprojfile
  2. Go to the final line, and before the tag, insert.
<Target Name="BeforeResolveReferences">
  <CreateProperty Value="$(MSBuildProjectDirectory)\two\levels\relativePath;$(AssemblySearchPaths)">
    <Output TaskParameter="Value" PropertyName="AssemblySearchPaths"/>
  </CreateProperty>
</Target>
Enter fullscreen mode Exit fullscreen mode
  1. Replace $(MSBuildProjectDirectory)\two\levels\relativePath; to your relative or absolute path.

References:

https://stackoverflow.com/questions/19309880/using-assemblysearchpaths-in-csproj-files/19456666
http://www.beefycode.com/post/resolving-binary-references-in-msbuild.aspx

Other references for deeper info:

https://docs.microsoft.com/en-us/visualstudio/msbuild/walkthrough-using-msbuild?view=vs-2019#targets-and-tasks
https://docs.microsoft.com/en-us/previous-versions/dotnet/netframework-2.0/9ad3f294(v=vs.80)?redirectedfrom=MSDN
https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-reserved-and-well-known-properties?view=vs-2019

Discussion (0)