Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem building SDK-style .NET Framework projects #23

Closed
daveaglick opened this issue Oct 24, 2017 · 4 comments
Closed

Problem building SDK-style .NET Framework projects #23

daveaglick opened this issue Oct 24, 2017 · 4 comments

Comments

@daveaglick
Copy link
Collaborator

Build started 10/24/2017 4:03:49 PM.
__________________________________________________
Project "E:\Code\Wyam.Web\release\repo\src\core\Wyam.Common\Wyam.Common.csproj" (Clean target(s)):


Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.87
Build started 10/24/2017 4:03:50 PM.
__________________________________________________
Project "E:\Code\Wyam.Web\release\repo\src\core\Wyam.Common\Wyam.Common.csproj" (Compile target(s)):

Target ImplicitlyExpandNETStandardFacades:
  C:\Program Files\dotnet\sdk\2.0.2\Microsoft\Microsoft.NET.Build.Extensions\Microsoft.NET.Build.Extensions.NETFramework.targets(48,5): error MSB4062: The "GetDependsOnNETStandard" task could not be loaded from the assembly C:\Program Files\dotnet\sdk\2.0.2\Microsoft\Microsoft.NET.Build.Extensions\\tools\net46\Microsoft.NET.Build.Extensions.Tasks.dll. Could not load file or assembly 'file:///C:\Program Files\dotnet\sdk\2.0.2\Microsoft\Microsoft.NET.Build.Extensions\tools\net46\Microsoft.NET.Build.Extensions.Tasks.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
Done building target "ImplicitlyExpandNETStandardFacades" in project "Wyam.Common.csproj" -- FAILED.

Done building project "Wyam.Common.csproj" -- FAILED.

Build FAILED.

C:\Program Files\dotnet\sdk\2.0.2\Microsoft\Microsoft.NET.Build.Extensions\Microsoft.NET.Build.Extensions.NETFramework.targets(48,5): error MSB4062: The "GetDependsOnNETStandard" task could not be loaded from the assembly C:\Program Files\dotnet\sdk\2.0.2\Microsoft\Microsoft.NET.Build.Extensions\\tools\net46\Microsoft.NET.Build.Extensions.Tasks.dll. Could not load file or assembly 'file:///C:\Program Files\dotnet\sdk\2.0.2\Microsoft\Microsoft.NET.Build.Extensions\tools\net46\Microsoft.NET.Build.Extensions.Tasks.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.16
@daveaglick
Copy link
Collaborator Author

It looks like the target checks the "$(MSBuildThisFileDirectory)\tools\net46" folder for Microsoft.NET.Build.Extensions.Tasks.dll:

https://github.com/dotnet/sdk/blob/cd25d6bbfc2aac61cc790c511900427ac64fdaa8/src/Tasks/Microsoft.NET.Build.Extensions.Tasks/msbuildExtensions/Microsoft/Microsoft.NET.Build.Extensions/Microsoft.NET.Build.Extensions.targets#L21

This folder exists at "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Sdks\Microsoft.NET.Sdk\tools\net46" when Visual Studio is installed, but not at "C:\Program Files\dotnet\sdk\2.0.2\Microsoft\Microsoft.NET.Build.Extensions\tools" (the latter only has a "netcoreapp1.0" subfolder). However, we set the MSBuild extensions folder to the dotnet SDK path if we detect an SDK project.

I guess it makes sense that .NET Framework projects should be using the VS build chain. It is called the .NET Core SDK after all. Suspect we'll need to check if the project targets .NET Framework and use the FrameworkPathHelper if so.

@daveaglick
Copy link
Collaborator Author

Interesting - it looks like the behavior is also different between an SDK project that targets net46 (which works) and one that targets net462 (which doesn't).

@dsplaisted
Copy link

MicrosoftMicrosoft.NET.Build.Extensions is used to support .NET Standard 2.0 when targeting .NET 4.6.1 and up. So it's not used if you're targeting .NET 4.6, because that doesn't support .NET Standard 2.0.

You should pretty much never use the targets in C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Sdks\Microsoft.NET.Sdk. Those targets correspond to the 1.x version of the SDK, so they won't work if you're trying to target .NET Standard 2.0 or .NET Core 2.0 or higher, and also don't have any other updates that came in the 2.0 SDK or later. You should use the versions from C:\Program Files\dotnet\sdk\, even if the project targets .NET Framework.

However, I don't know if you need to explicitly point MSBuild to those targets. MSBuild has a built-in Sdk import resolver which will find those targets. I don't know if it will be automatically used when you are just using the MSBuild APIs. It is installed under C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\SdkResolvers, so you may want to point MSBuild at that resolver instead of pointing it directly at the SDK props and targets files (that way it will respect global.json and any other logic that is normally used to find those files).

@daveaglick
Copy link
Collaborator Author

@dsplaisted Thanks a bunch, that does help. Especially the bit about a custom resolver. After popping it open in a decompiler I can see how the VS toolchain finds the SDK.

Based on what you said about the targets in the VS Sdks directory, I'll use the VS toolchain for building .NET Framework SDK projects but set MSBuildSDKsPath to the .NET Core SDK. Hopefully that'll give the right combination of targets for these types of projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants