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

Restoring with invalid target framework says 'unsupported' instead of showing bad framework name #5413

Closed
nguerrera opened this issue Jun 14, 2017 · 6 comments
Assignees
Labels
Functionality:Restore Priority:2 Issues for the current backlog.
Milestone

Comments

@nguerrera
Copy link

Given <TargetFramework>abc123</TargetFramework>, RestoreTask yields:

C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets(102,5): 
error : Invalid restore input. Invalid target framework 'unsupported'. Input files: D:\Temp\qwerty\qwerty.csproj. [D:\Temp\qwerty\qwerty.csproj]

It should indicate the badly spelled framework 'abc13' in the error message instead of 'unsupported'.

We tried to fix this by running our own check before restore in the SDK, but that breaks adding support for additional TFMs like uap using the MSBuild.Sdk.Extras package.

@emgarten
Copy link
Member

Good catch, it looks like we throw this error later after parsing the framework and lose the original. This should be fixed.

@emgarten emgarten added this to the Future-0 milestone Jun 15, 2017
@mishra14 mishra14 modified the milestones: Future-0, Backlog Nov 30, 2017
@mishra14 mishra14 added the Priority:2 Issues for the current backlog. label Nov 30, 2017
@KirillOsenkov
Copy link

Similar issue, not sure if the same:

Restore a project with Microsoft.NET.Sdk that doesn't specify TargetFramework at all. You will get a pretty obscure error message:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targe
ts(119,5): error : Invalid framework identifier ''. [C:\Temp\1.proj]

It should probably fail earlier with a better error message, when it can't retrieve the TargetFramework from a project.

Right now it fails too late, with this stack:

>	NuGet.Frameworks.dll!NuGet.Frameworks.NuGetFramework.GetShortFolderName(NuGet.Frameworks.IFrameworkNameProvider mappings) Line 166	C#
 	NuGet.Frameworks.dll!NuGet.Frameworks.NuGetFramework.GetShortFolderName() Line 141	C#
 	NuGet.ProjectModel.dll!NuGet.ProjectModel.PackageSpecWriter.SetMSBuildMetadata.AnonymousMethod__3_1(string e) Line 151	C#
 	System.Core.dll!System.Linq.Enumerable.WhereSelectListIterator<string, string>.MoveNext() Line 486	C#
 	System.Core.dll!System.Linq.Buffer<string>.Buffer(System.Collections.Generic.IEnumerable<string> source) Line 2681	C#
 	System.Core.dll!System.Linq.OrderedEnumerable<string>.GetEnumerator() Line 2544	C#
 	System.Core.dll!System.Linq.Enumerable.Any<string>(System.Collections.Generic.IEnumerable<string> source) Line 1291	C#
 	NuGet.ProjectModel.dll!NuGet.ProjectModel.PackageSpecWriter.SetArrayValue(NuGet.RuntimeModel.IObjectWriter writer, string name, System.Collections.Generic.IEnumerable<string> values) Line 503	C#
 	NuGet.ProjectModel.dll!NuGet.ProjectModel.PackageSpecWriter.SetMSBuildMetadata(NuGet.RuntimeModel.IObjectWriter writer, NuGet.ProjectModel.PackageSpec packageSpec) Line 154	C#
 	NuGet.ProjectModel.dll!NuGet.ProjectModel.PackageSpecWriter.Write(NuGet.ProjectModel.PackageSpec packageSpec, NuGet.RuntimeModel.IObjectWriter writer) Line 56	C#
 	NuGet.ProjectModel.dll!NuGet.ProjectModel.DependencyGraphSpec.Write(NuGet.RuntimeModel.IObjectWriter writer, System.Action<NuGet.ProjectModel.PackageSpec, NuGet.RuntimeModel.IObjectWriter> writeAction) Line 326	C#
 	NuGet.ProjectModel.dll!NuGet.ProjectModel.DependencyGraphSpec.GetJson() Line 248	C#
 	NuGet.ProjectModel.dll!NuGet.ProjectModel.DependencyGraphSpec.Save(string path) Line 233	C#
 	NuGet.Commands.dll!NuGet.Commands.NoOpRestoreUtilities.PersistDGSpecFile(NuGet.ProjectModel.DependencyGraphSpec spec, NuGet.Commands.RestoreRequest request, NuGet.Common.ILogger log) Line 244	C#
 	NuGet.Commands.dll!NuGet.Commands.NoOpRestoreUtilities.GetHash(NuGet.Commands.RestoreRequest request) Line 229	C#
 	NuGet.Commands.dll!NuGet.Commands.RestoreCommand.EvaluateCacheFile() Line 509	C#
 	NuGet.Commands.dll!NuGet.Commands.RestoreCommand.ExecuteAsync(System.Threading.CancellationToken token) Line 124	C#
 	NuGet.Commands.dll!NuGet.Commands.RestoreRunner.ExecuteAsync(NuGet.Commands.RestoreSummaryRequest summaryRequest, System.Threading.CancellationToken token) Line 262	C#
 	NuGet.Commands.dll!NuGet.Commands.RestoreRunner.ExecuteAndCommitAsync(NuGet.Commands.RestoreSummaryRequest summaryRequest, System.Threading.CancellationToken token) Line 236	C#
 	NuGet.Commands.dll!NuGet.Commands.RestoreRunner.RunAsync.AnonymousMethod__0() Line 84	C#

Instead it should validate inputs earlier, somewhere here. See how TargetFramework is an empty string:

image

Maybe even avoid calling RestoreTask in that case.

@KirillOsenkov
Copy link

Aha, I see the GetProjectTargetFrameworksTask should probably be the one reporting an error:

image

@KirillOsenkov

@rrelyea
Copy link
Contributor

rrelyea commented Mar 4, 2020

consider as part of net5.0tfm work

@wackoisgod
Copy link

wackoisgod commented Apr 28, 2020

@rrelyea What is the status of this? I ask because I am running into an issue where when I build a solution file in VS the output of the dg file is different then say I use msbuild /t:Restore or dotnet build for a given solution file.

I currently have a custom TFM, and based on the debugging I have done I can't see how the framework parsing for nuget would even know about my custom Tfm, but then again the dg file does generate something in VS.

within VS:

"frameworks": {
          "unitydots20": {
            "projectReferences": {}
}

but with msbuild or dotnet I get:

"frameworks": {
          "unsupported": {
            "projectReferences": {}
}

it looks like when running from within VS it uses the ParseFrameworkName function where as running from the commandline it uses ParseFolder.

Actually seems like VS is using the NugetTargetMoniker if its set

@nkolev92
Copy link
Member

nkolev92 commented Dec 2, 2021

With 6.0, dotnet restore does;

 dotnet restore
  Determining projects to restore...
C:\Program Files\dotnet\sdk\6.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(92,5): error NETSDK1013: The TargetFramework value 'abc123' was not recognized. It may be misspelled. If not, then the TargetFrameworkIdentifier and/or TargetFrameworkVersion properties must be specified explicitly. [C:\Code\Temp\invalid\invalid.csproj]

In VS you'd get:

NuGet package restore failed. Please see Error List window for detailed warnings and errors.
Time Elapsed: 00:00:00.3912640
========== Finished ==========


Error occurred while restoring NuGet packages: Invalid restore input. Invalid target framework 'unsupported'. Input files: C:\Code\Temp\invalid\invalid.csproj.

But you still get the SDK error.

As such, I think this can be considered fixed.

@nkolev92 nkolev92 closed this as completed Dec 2, 2021
@nkolev92 nkolev92 reopened this Dec 2, 2021
@nkolev92 nkolev92 closed this as completed Dec 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Functionality:Restore Priority:2 Issues for the current backlog.
Projects
None yet
Development

No branches or pull requests

8 participants