Search code examples
visual-studioazure-devopsmsbuilddependenciesazure-pipelines

Azure pipeline: msbuild does not copy one DLL in _PublishedWebsites


I have a strange behavior with msbuild on my Azure Pipeline. I'm using Azure Pipeline with Self-hosted Windows agents.

Configuration:

My Visual Studio .sln contains two C# projects:

  • WebService (Rest API)
  • Business layer

In addition, the Business layer has dependencies on 2 others projects.

  • Kernel.DataModel
  • Kernel.DataAccess

The Kernel.DataAcess layer is using the NuGet package "Microsoft.SqlServer.Types" (14.0.314.76)

The Reference "Microsoft.SqlServer.Types" in the project Kernel.DataAccess has "Copy Local = True". Therefore the DLL file should be copied in the output (release) directory.

The problem:

When I run the Azure Build pipeline, the file "Microsoft.SqlServer.Types.dll" is not copied in the "_PublishedWebsites" directory.

To convince myself, I decided to run the same Pipeline on another build machine by changing the Agent Pool. At my surprise the DLL was present in the "_PublishedWebsites" on the second build machine.

Furthermore, I decided to manually run the msbuild command on my local computer and the the DLL was also present in the "_PublishedWebsites...\bin" on my local machine.

Log files:

I also looked at log files on the Build machines and on my local computer.

  • First build machine -> The DLL file is simply not copied !

  • Second build machine -> The DLL file is copied from this location.

Copying file from "C:\Program Files (x86)\Microsoft SQL Server\140\SDK\Assemblies\Microsoft.SqlServer.Types.dll" to "F:\AgentLatestBuild\A1\_work\28\b\_PublishedWebsites\ApiProject\bin\Microsoft.SqlServer.Types.dll".
  • Local machine ->
_CopyFilesMarkedCopyLocal:
Copying file from "C:\TFS\Repos\Src\Project\**packages**\Microsoft.SqlServer.Types.14.0.314.76\lib\net40\Microsoft.SqlServer.Types.dll" to "E:\tfs\build\Microsoft.SqlServer.Types.dll".

Copying file from "E:\tfs\build\Microsoft.SqlServer.Types.dll" to "E:\tfs\build\_PublishedWebsites\ApiProject\bin\Microsoft.SqlServer.Types.dll".

As you can see: On the second build machine, msbuild is not using the NuGet packages folder but it's using "C:\Program Files (x86)\Microsoft SQL Server\140\SDK\Assemblies\Microsoft.SqlServer.Types.dll"

On my local machine, the DLL is copied from the NuGet packages folder.

Here are my questions:

How msbuild.exe is selecting the source/location of the DLL ?

Is there a way to force msbuild to first use the NuGet packages instead of any others folders ?

I think msbuild should first look in the NuGet packages folder and if the DLL is not found, then it should try to find it from somewhere else. (C:\Program Files (x86), GAC, etc..)

Finally, do you have any idea why the "Microsoft.SqlServer.Types.dll" is not copied at all on the first build machine. The DLL is present in at least three locations. (ie: NuGet packages folder, C:\Program files\ and it is also in the GAC).

It looks like msbuild is lost in the dependency tracking and can't find the file or it won't copy it for some other reasons.

Thanks for your help.


Solution

  • Is it possible that your *.csproj is targetting the wrong HintPath?

    Could you check if you have something like this:

        <Reference Include="Microsoft.SqlServer.Types">
          <HintPath>..\packages\Microsoft.SqlServer.Types.YOURVERSION\lib\net40\Microsoft.SqlServer.Types.dll</HintPath>
        </Reference>
    

    thanks