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

Fix invalid target framework error for Solution restore #6091

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

martinrrm
Copy link
Contributor

@martinrrm martinrrm commented Oct 9, 2024

Bug

Fixes: NuGet/Home#13772

Description

There is a difference in behavior when doing a restore in Solution vs Project with an invalid target framework in the <TargetFramework> tag. When doing it in the project Level, sdk will run a validation before doing restore in https://github.com/dotnet/sdk/blob/5ab26633bdf4676efa25140a31a3d6182efb02f9/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.TargetFrameworkInference.targets#L92.

The problem is that Solution level does not this validation (since it doesn't run a restore for each project) and will fail with

...\Current\bin\NuGet.targets(169,5): error : Sequence contains no matching element [<repo>\dirs.proj]

This PR adds a validation and return the same error message as the project level. Currently, I decided to error with a NuGet error but we could also add NETSDK1046 in the error message.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@martinrrm martinrrm changed the title add check in nuget.targets Fix invalid target framework error for Solution restore Oct 9, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed labels Oct 21, 2024
@dotnet-policy-service dotnet-policy-service bot removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Oct 21, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Oct 28, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed labels Oct 29, 2024
@martinrrm martinrrm marked this pull request as ready for review October 29, 2024 22:03
@martinrrm martinrrm requested a review from a team as a code owner October 29, 2024 22:03
Copy link
Member

@nkolev92 nkolev92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some test failures that seem like actual failures.
It's also worth calling out in the description that this is only a CLI problem in the PR description and that VS errors are way better.

@@ -458,6 +458,12 @@ private static IEnumerable<TargetFrameworkInformation> GetTargetFrameworkInforma
foreach (var item in GetItemByType(items, "TargetFrameworkInformation"))
{
var frameworkString = item.GetProperty("TargetFramework");
if (frameworkString.Contains(';'))
Copy link
Member

@nkolev92 nkolev92 Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing from here probably leads to a bad failure in NuGet.exe?

In general, NuGet.exe expects a dg spec to create an this fails that.

Can you double check NuGet.exe?

[Theory]
[InlineData("net40;net45")]
[InlineData("net40;net45 ; netstandard2.0 ")]
public void GetOriginalTargetFramework_WhenTargetFramworkSpecified_HasCorrectTargetFramework(string targetFrameworks)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public void GetOriginalTargetFramework_WhenTargetFramworkSpecified_HasCorrectTargetFramework(string targetFrameworks)
public void GetOriginalTargetFramework_WhenMultipleTargetFramworkSpecified_ThrowRestoreCommandException(string targetFrameworks)

Might want to change the name of this test.

This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 7 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Sequence contains no matching element" when using a bad TF
3 participants