-
Notifications
You must be signed in to change notification settings - Fork 5k
disable restore in vs for projects targeting platform specific old frameworks #44932
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
Conversation
Tagging subscribers to this area: @safern, @ViktorHofer Issue DetailsFixes #32205
official docs https://docs.microsoft.com/en-us/nuget/consume-packages/package-restore
|
I think it would be great if we could also add a script that automats and eventually protects this (in combination with my slngen script):
If you don't mind, I will push into your branch to add that logic. |
src/libraries/Microsoft.Win32.Registry.AccessControl/NuGet.config
Outdated
Show resolved
Hide resolved
sure go ahead |
Ok, I'll get to it on Monday. Let's keep this open till then so that I can verify your change with the script. |
@ViktorHofer any update on this one ? |
hopefully I'll get to it tomorrow. |
@Anipik just pushed the code into your PR. Seems like there were a few NuGet.config files missing which are now also part of the PR. @akoeplinger I also addressed your feedback and converted the ps1 script into a proj file. |
Ok not quite there. System.Windows.Extensions is not discovered by the script. |
OK the script is working fine, it just didn't update the file as it was already there with the same content. Here's the list of slns in which restore is now disabled:
|
OK so PR is ready now. The scripts shows that the validation was important. One NuGet.config file was too much ( |
Outputs="%(Identity)"> | ||
<!-- Check if project file contains duplicate tfms --> | ||
<PropertyGroup> | ||
<ProjectFileContent>$([System.IO.File]::ReadAllText('%(SourceProject.Identity)'))</ProjectFileContent> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we doing this instead of just calling a target in the project? Is it for perf? Is there a way to do a faster load of a project (eg: skipping imports or something) to improve perf, but still get MSBuild do the parsing/eval of the project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There isn't a target in the SDK currently that returns the TargetFrameworks string in its raw form which we need in this case. I also wouldn't want to call into msbuild to eval/parse the project as it just isn't worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you concerned with folks using properties in the TargetFrameworks string or using something that fools these regexs?
A couple small comments on the method, if you keep the regex approach, avoid raising the entire project content to a property, instead feed it directly into the regex. Also, it seems like your regex is already matching the TargetFrameworks tags, so you should be able to avoid using string.Replace calls by setting property to the captured content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, it seems like your regex is already matching the TargetFrameworks tags, so you should be able to avoid using string.Replace calls by setting property to the captured content.
Unfortunately using Regex.Match as a property function doesn't allow to specify an inner capture group. It only returns the full capture which includes the boundaries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you concerned with folks using properties in the TargetFrameworks string or using something that fools these regexs?
Not at all, I tested it with properties as well. It works with the inlined values or with the markers like $(NetCoreAppCurrent)
. I'm not concerned about derived properties as we don't have those today and it's less likely that we will add ones for anything older than net5.0.
If we would ever need full evaluation of it, we can switch to a different model of course :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thing. I spoke with Rainer about this and there currently isn't a way from within msbuild to do this without writing a task which I wanted to avoid. There's a proposal though: dotnet/msbuild#3911.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, really last comment. The TargetFramework.Sdk today mutates the TargetFrameworks property which is yet another reason why I don't want to depend on the evaluated values. As I see this project as a mitigator for a point in time problem, I'm ok with the solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair. You might be able to use Regex replace instead of match in order to use a capture group.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's possible but if you don't mind I would just leave as is as CI is already green and this would only be code clean-up (removing two lines). But appreciate the feedback :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, this is less blocking since this is just a manually run tool
Fixes #32205
official docs https://docs.microsoft.com/en-us/nuget/consume-packages/package-restore