fuglede
fuglede

Reputation: 18221

.NET 5.0 publish gives CS0006 dll could not be found for .NET Standard 2.0 dependency

I have a .NET 5.0 project, ProjectA, which depends on a .NET Standard 2.0 project, ProjectB. I can build and run the .NET 5.0 including its dependency without issues. The two projects are stored in the same root folder, and relying only on default configurations, the resulting libraries end up in

ProjectB\bin\Release\netstandard2.0\ProjectB.dll
ProjectA\bin\Release\net5.0\ProjectA.dll

as expected.

If I use the VS Pro 2019 v16.8.6 UI to publish the .NET 5.0 project, however, using the publish profile

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <DeleteExistingFiles>False</DeleteExistingFiles>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <PublishProvider>FileSystem</PublishProvider>
    <PublishUrl>{{ my-url }}</PublishUrl>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <SiteUrlToLaunchAfterPublish />
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <ProjectGuid>{{ my-guid }}</ProjectGuid>
    <SelfContained>true</SelfContained>
    <PublishSingleFile>True</PublishSingleFile>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>
</Project>

I end up getting the error that

CSC(0,0): Error CS0006: Metadata file 'ProjectB\bin\Release\netstandard2.0\win-x64\ProjectB.dll' could not be found

The build that precedes the publish still builds ProjectB as expected, but still leaves it in netstandard2.0, as opposed to netstandard2.0\win-x64 where the publish step is looking. I can add a build step to manually copy the built ProjectB files to the win-x64 but that's pretty clunky.

Is there a way to tweak the publish configuration so it looks for the dependency in the right place?

The closest related StackOverflow post is this one, in which we encounter the same issue in a different context, and in which the solution was to get rid of TargetFramework in the publish profile. Doing so does not resolve the issue in my case.

Interestingly, dotnet publish -r win-x64 (from .NET SDK (5.0.104)) figures out where to look for the ProjectB files, so that works, but seems unable to use the pubxml above (cf. also this SO question, for which none of the given answers work here).

Upvotes: 1

Views: 856

Answers (1)

fuglede
fuglede

Reputation: 18221

Updating Visual Studio (from 16.8.6 to 16.9.2) fixed the issue, so presumably this was simply a bug in the earlier version of Visual Studio.

Upvotes: 0

Related Questions