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

GeneratePathProperty properties should end with a trailing slash #8871

Open
rainersigwald opened this issue Dec 3, 2019 · 16 comments · Fixed by NuGet/NuGet.Client#4384
Open
Labels
Category:Quality Week Issues that should be considered for quality week Functionality:Restore Partner:MSBuild Priority:2 Issues for the current backlog. Style:PackageReference Type:DCR Design Change Request

Comments

@rainersigwald
Copy link

Details about Problem

NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe): msbuild -t:Restore

NuGet version (x.x.x.xxx): 5.5.0-preview.1.6319+ba2a72ac9afd9e7260798a6ad14088297570b350.ba2a72ac9afd9e7260798a6ad14088297570b350

Worked before? If so, with which NuGet version: no

Detailed repro steps so we can see the same problem

When a package is referenced with GeneratePathProperty="true", a property based on the package name is created in .nuget.g.props. The value of the property is the path to the root of the expanded package on disk.

Currently, this looks like

  <PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
    <PkgEnterpriseLibrary_TransientFaultHandling_Core Condition=" '$(PkgEnterpriseLibrary_TransientFaultHandling_Core)' == '' ">C:\Users\raines\.nuget\packages\enterpriselibrary.transientfaulthandling.core\1.0.0</PkgEnterpriseLibrary_TransientFaultHandling_Core>
  </PropertyGroup>

Ideally this would end with a path-separator slash. That makes it easier to avoid referencing the property with a glob like $(PkgWhatever)\** which expands to {root of disk}\** which causes MSBuild to read every file on the disk, with possibly destructive effects. If the property is undefined $(PkgWhateverWithTrailingSlash)** is at least restricted to the project directory.

Various properties in common targets follow this convention for this reason.

Other suggested things

An obvious question is "should MSBuild allow this?". It's hard to definitively say "no", but we're considering logging and some other options: dotnet/msbuild#3642 dotnet/msbuild#3204

@donnie-msft
Copy link
Contributor

@jeffkl can you provide some input on this one?

@donnie-msft donnie-msft added Triage:NeedsTriageDiscussion Partner:MSBuild WaitingForCustomer Applied when a NuGet triage person needs more info from the OP labels Dec 3, 2019
@jeffkl
Copy link
Contributor

jeffkl commented Dec 3, 2019

Knowing that the paths are always directories, it would fine to add the trailing slash. It probably should have had it from the beginning.

@nkolev92
Copy link
Member

nkolev92 commented Dec 3, 2019

This would be a breaking change then, correct?
How have we handled migrations of similar behavior before?

@jeffkl
Copy link
Contributor

jeffkl commented Dec 3, 2019

I don't believe it would be a breaking change. If people consumed the properties like:

<PropertyGroup>
  <MyNewProperty>$(Pkg_SomePackage)\somepath</MyNewProperty>
</PropertyGroup>

Then they'd end up with an extra slash which shouldn't cause any issues, even if they used relative paths like $(Pkg_SomePackage)\..\subdir. At least on Windows, the extra slash is ignored.

@nkolev92
Copy link
Member

nkolev92 commented Dec 3, 2019

At least on Windows, the extra slash is ignored.

Key point :)

@jeffkl
Copy link
Contributor

jeffkl commented Dec 4, 2019

I have verified that on linux, the double directory separated is also ignored

jeff@JEFFKL-DEV:/$ ls home//jeff//dotnet-install.sh
home//jeff//dotnet-install.sh

jeff@JEFFKL-DEV:/$ cat /etc/os-release
NAME="Ubuntu"
VERSION="18.04.2 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.2 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

@donnie-msft donnie-msft removed the WaitingForCustomer Applied when a NuGet triage person needs more info from the OP label Dec 14, 2019
@nkolev92 nkolev92 added Category:Quality Week Issues that should be considered for quality week Pipeline:Backlog Priority:2 Issues for the current backlog. and removed Triage:NeedsTriageDiscussion Pipeline:New Issues labels May 1, 2020
@nkolev92 nkolev92 self-assigned this Jul 24, 2020
@nkolev92 nkolev92 removed their assignment Nov 6, 2020
@zkat
Copy link
Contributor

zkat commented Jan 20, 2021

This seems small enough that we can probably keep in .NET 6. /cc @aortiz-msft because we might need scheduling for it, if it's going to stay in the epic

@zkat zkat self-assigned this May 7, 2021
@zkat zkat mentioned this issue Jul 1, 2021
5 tasks
@zkat zkat added this to the Sprint 2021-07 milestone Jul 6, 2021
@zkat
Copy link
Contributor

zkat commented Jul 12, 2021

Pushing this into #10846 but we'll likely get it done before then. It just won't go into net6.0 GA, most likely.

@zkat zkat mentioned this issue Jul 12, 2021
8 tasks
@JonDouglas JonDouglas changed the title GeneratePathProperty properties should end with a trailing slash B Oct 21, 2021
@JonDouglas JonDouglas changed the title B GeneratePathProperty properties should end with a trailing slash Oct 21, 2021
@JonDouglas
Copy link
Contributor

Apologies. Using a beta project that apparently updates titles on a keystroke.

@aortiz-msft
Copy link
Contributor

@jeffkl - Would you mind fixing this sprint as part of Quality Week?

@jeffkl
Copy link
Contributor

jeffkl commented Jan 4, 2022

@aortiz-msft sure thing: NuGet/NuGet.Client#4384

@Forgind
Copy link

Forgind commented Apr 7, 2022

Turns out this was a breaking change:
https://developercommunity.visualstudio.com/t/Robocopy-command-exited-with-code--1/1690181#T-ND10008741

If an argument is supposed to be a folder, and you pass it quoted, the \" is treated as an escaped quote instead of the end of the path, and you get errors.

I'm sure there are other tools that do something similar.

@jeffkl
Copy link
Contributor

jeffkl commented Apr 12, 2022

We are going to revert NuGet/NuGet.Client#4384 since it turned into a breaking change (#11737)

@jeffkl jeffkl reopened this Apr 12, 2022
@Nirmal4G
Copy link

Can't it be opt-in or opt-out for the time being?

@Forgind
Copy link

Forgind commented Apr 25, 2022

Can't it be opt-in or opt-out for the time being?

Up to NuGet, but in my opinion, that would just make it more confusing. You'd have to make it opt-in or opt-out when the property is set but use it (without getting to opt-in or -out) in other files, so if you don't want any extra slashes, you might have something like:

...$(PkgMy_Package)\rest_of_path
...$(PkgMy_Other_Package)rest_of_path

People seeing just one line would often get it wrong if they copy/paste...

@Nirmal4G
Copy link

Nirmal4G commented Apr 25, 2022

So, if it has to be a breaking change, then better do it for all built-in/generated properties, I guess. This can go so wrong in so many ways 🤯 that I can't begin to describe it, if not done properly. MSBuild itself is resilient (almost) but not the external commands we pass the properties to. This is tricky!

@jeffkl jeffkl removed their assignment Mar 17, 2023
@nkolev92 nkolev92 removed this from the Sprint 2022-01 milestone Mar 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category:Quality Week Issues that should be considered for quality week Functionality:Restore Partner:MSBuild Priority:2 Issues for the current backlog. Style:PackageReference Type:DCR Design Change Request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants