0
votes

I have the follow set of projects in my solution:
1) A .NET framework (4.7.1) project that produces an assembly. "Project A"
2) A ASP.NET core MVC based web api project based on .NET Core 2.1. "Project B"

Project B references Project A, building the solution via Visual Studio 2017 does not lead to any issues. However if I try and build the solution via msbuild using the following command, I am unable to compile Project B:

"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe" D:\Stuff\MySolution.sln" /p:Platform=x64 /p:Configuration=Debug /v:m /clp:Summary

Errors in D:\Stuff\ProjectB\ProjectB.csproj
Unable to resolve 'D:\Stuff\ProjectA\ProjectA.csproj for '.NETCoreApp,Version=v2.1'
Unable to resolve 'D:\Stuff\ProjectA\ProjectA.csproj for '.NETCoreApp,Version=v2.1 (win-x64)'

ProjectB's property group looks like this:

<PropertyGroup>
 <TargetFramework>netcoreapp2.1</TargetFramework>
 <RuntimeFrameworkVersion>2.1.0</RuntimeFrameworkVersion>
 <PlatformTarget>AnyCPU</PlatformTarget>
 <ProjectGuid>{D41E3CAE-2EE3-4BED-8965-50AF8C243A20}</ProjectGuid>
 <RootNamespace>com.ProjectB</RootNamespace>
 <AssemblyName>com.ProjectB</AssemblyName>
 <RuntimeIdentifier>win-x64</RuntimeIdentifier>
</PropertyGroup>

And also has the following PackageReference:

<ItemGroup>
 <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.0"/>
</ItemGroup>

It is as if MSBuild is trying to apply the target framework defined in ProjectB to ProjectA, however as mentioned before this does not happen in Visual Studio.

1
Why do you want a .NET Core project to depend on a .NET Framework project? blog.lextudio.com/…Lex Li
The plan is to eventually move it to core as well but initially it has to stay .NET based.user1628056
Given that, you created a wrong .NET Core project. Please try again to create an ASP.NET Core project targeting .NET Framework. However, keep in mind that ASP.NET Core on .NET Framework is no longer supported on .NET Core 3 and above.Lex Li
@Lex Li But the question is why does it work fine if I compile it via Visual Studio? It runs fine and I can debug it etc. The only thing that does not work is compiling it via MSbuild so I am probably not configuring something correctly I assume?user1628056
@LanceLi-MSFT Unfortunately I was never able to find a proper solution to the issue, so I ended up converting the .NET Core project to a regular .NET framework project, this made it work on MSBuild, the original issue still persists so I can't really offer an answer.user1628056

1 Answers

0
votes

From the error message, it seems that Project B depend on Project A.

You can't reference to a .NET Framework project from .NET Core project. And this sis an answer.

Now, why in Visual Studio it can build? There may be missing details in the question, or the compilation is not the same compilation that you are trying to perform.