Skip to content

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

Merged
merged 5 commits into from
Dec 2, 2020

Conversation

Anipik
Copy link
Contributor

@Anipik Anipik commented Nov 19, 2020

Fixes #32205

  • Command line restore still works.
  • disables these flags just for these slns, not on the whole repo level.
  • the error message now will be to just run restore for test projects from the cli for older platform specific frameworks

official docs https://docs.microsoft.com/en-us/nuget/consume-packages/package-restore

@ghost
Copy link

ghost commented Nov 19, 2020

Tagging subscribers to this area: @safern, @ViktorHofer
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #32205

  • Command line restore still works.
  • disables these flags just for these slns, not on the whole repo level.
  • the error message now will be to just run restore for test projects from the cli for older platform specific frameworks

official docs https://docs.microsoft.com/en-us/nuget/consume-packages/package-restore

Author: Anipik
Assignees: -
Labels:

area-Infrastructure-libraries

Milestone: -

@Anipik Anipik changed the title disable vs restore in vs for projects targeting platform specific old frameworks disablerestore in vs for projects targeting platform specific old frameworks Nov 19, 2020
@Anipik Anipik changed the title disablerestore in vs for projects targeting platform specific old frameworks disable restore in vs for projects targeting platform specific old frameworks Nov 19, 2020
@ViktorHofer
Copy link
Member

ViktorHofer commented Nov 19, 2020

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):

  1. Grep all src project TargetFrameworks and search for duplicate tfms < net5.0, save that information in a list.
  2. Scan if solution files contain one of the items from the list.
  3. Add the NuGet.config template to the leafs that are affected.

If you don't mind, I will push into your branch to add that logic.

@Anipik
Copy link
Contributor Author

Anipik commented Nov 19, 2020

If you don't mind, I will push into your branch to add that logic.

sure go ahead

@ViktorHofer
Copy link
Member

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.

@Anipik
Copy link
Contributor Author

Anipik commented Nov 30, 2020

@ViktorHofer any update on this one ?

@ViktorHofer
Copy link
Member

hopefully I'll get to it tomorrow.

@ViktorHofer
Copy link
Member

@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.

@ViktorHofer
Copy link
Member

Ok not quite there. System.Windows.Extensions is not discovered by the script.

@ViktorHofer
Copy link
Member

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:

Copying NuGet.config template file for Microsoft.Extensions.Configuration.Xml
  Copying NuGet.config template file for Microsoft.Extensions.Configuration
  Copying NuGet.config template file for Microsoft.Extensions.Hosting
  Copying NuGet.config template file for Microsoft.Extensions.Logging.EventLog
  Copying NuGet.config template file for Microsoft.Extensions.Logging
  Copying NuGet.config template file for Microsoft.VisualBasic.Core
  Copying NuGet.config template file for Microsoft.Win32.Registry.AccessControl
  Copying NuGet.config template file for Microsoft.Win32.Registry
  Copying NuGet.config template file for System.Configuration.ConfigurationManager
  Copying NuGet.config template file for System.Data.Odbc
  Copying NuGet.config template file for System.Data.Oledb
  Copying NuGet.config template file for System.Diagnostics.EventLog
  Copying NuGet.config template file for System.Diagnostics.PerformanceCounter
  Copying NuGet.config template file for System.Diagnostics.Process
  Copying NuGet.config template file for System.DirectoryServices.AccountManagement
  Copying NuGet.config template file for System.DirectoryServices.Protocols
  Copying NuGet.config template file for System.DirectoryServices
  Copying NuGet.config template file for System.Drawing.Common
  Copying NuGet.config template file for System.IO.FileSystem.AccessControl
  Copying NuGet.config template file for System.IO.IsolatedStorage
  Copying NuGet.config template file for System.IO.Pipes.AccessControl
  Copying NuGet.config template file for System.IO.Pipes
  Copying NuGet.config template file for System.IO.Ports
  Copying NuGet.config template file for System.Management
  Copying NuGet.config template file for System.Net.Http.WinHttpHandler
  Copying NuGet.config template file for System.Net.HttpListener
  Copying NuGet.config template file for System.Net.Http
  Copying NuGet.config template file for System.Net.Mail
  Copying NuGet.config template file for System.Net.NameResolution
  Copying NuGet.config template file for System.Net.Requests
  Copying NuGet.config template file for System.Net.Security
  Copying NuGet.config template file for System.Net.Sockets
  Copying NuGet.config template file for System.Resources.Extensions
  Copying NuGet.config template file for System.Resources.ResourceManager
  Copying NuGet.config template file for System.Runtime.Caching
  Copying NuGet.config template file for System.Runtime.Serialization.Formatters
  Copying NuGet.config template file for System.Runtime
  Copying NuGet.config template file for System.Security.AccessControl
  Copying NuGet.config template file for System.Security.Cryptography.Algorithms
  Copying NuGet.config template file for System.Security.Cryptography.Cng
  Copying NuGet.config template file for System.Security.Cryptography.Csp
  Copying NuGet.config template file for System.Security.Cryptography.OpenSsl
  Copying NuGet.config template file for System.Security.Cryptography.Pkcs
  Copying NuGet.config template file for System.Security.Cryptography.ProtectedData
  Copying NuGet.config template file for System.Security.Cryptography.X509Certificates
  Copying NuGet.config template file for System.Security.Cryptography.Xml
  Copying NuGet.config template file for System.Security.Permissions
  Copying NuGet.config template file for System.Security.Principal.Windows
  Copying NuGet.config template file for System.ServiceProcess.ServiceController
  Copying NuGet.config template file for System.Text.Encoding.CodePages
  Copying NuGet.config template file for System.Threading.AccessControl
  Copying NuGet.config template file for System.Windows.Extensions

@ViktorHofer ViktorHofer closed this Dec 2, 2020
@ViktorHofer ViktorHofer reopened this Dec 2, 2020
@ViktorHofer
Copy link
Member

OK so PR is ready now. The scripts shows that the validation was important. One NuGet.config file was too much (Microsoft.Win32.SystemEvents) and about 25 were missing.

Outputs="%(Identity)">
<!-- Check if project file contains duplicate tfms -->
<PropertyGroup>
<ProjectFileContent>$([System.IO.File]::ReadAllText('%(SourceProject.Identity)'))</ProjectFileContent>
Copy link
Member

@ericstj ericstj Dec 2, 2020

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?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

@ViktorHofer ViktorHofer Dec 2, 2020

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 :)

Copy link
Member

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.

Copy link
Member

@ViktorHofer ViktorHofer Dec 2, 2020

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.

Copy link
Member

@ericstj ericstj Dec 2, 2020

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.

Copy link
Member

@ViktorHofer ViktorHofer Dec 2, 2020

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 :)

Copy link
Member

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

@ghost ghost locked as resolved and limited conversation to collaborators Jan 1, 2021
@Anipik Anipik deleted the nuget branch January 30, 2021 21:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove duplicates From the TargetFrameworks while doing restore.
4 participants