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

Executables restored from NuGet packages are no longer executable with .NET Core "2.0" #4424

Closed
eerhardt opened this issue Jan 28, 2017 · 45 comments

Comments

@eerhardt
Copy link

Details about Problem

NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe):

Erics-MBP:cli eerhardt$ ./.dotnet_stage0/x64/dotnet --info
.NET Command Line Tools (2.0.0-alpha-004622)

Product Information:
 Version:            2.0.0-alpha-004622
 Commit SHA-1 hash:  1f44cabf4a

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.12
 OS Platform: Darwin
 RID:         osx.10.11-x64

Worked before? If so, with which NuGet version: Yes, with dotnet restore version 1.0.0-rc3-004530.

Detailed repro steps so we can see the same problem

  1. Install a "2.0" CLI from https:/dotnet/cli/tree/master#installers-and-binaries on a non-Windows machine.

  2. Restore a package that contains a tool/executable. For example, Microsoft.NETCore.Runtime.CoreCLR version 1.2.0-beta-24904-03.

  3. Try to execute the crossgen executable at .nuget/packages/runtime.osx.10.10-x64.microsoft.netcore.runtime.coreclr/1.2.0-beta-24904-03/tools/crossgen

Expected result:

With "1.0", the executable would run.

Actual result:

15:57:11.104     1>/Users/dotnet-bot/j/workspace/dotnet_cli/master/release_osx_x64_prtest/build/Microsoft.DotNet.Cli.Compile.targets(225,7): error MSB6003: The specified task executable "crossgen" could not be run. Operation not permitted [/Users/dotnet-bot/j/workspace/dotnet_cli/master/release_osx_x64_prtest/build.proj]

Notes

The regression is caused by System.IO.Compression in corefx. See https:/dotnet/corefx/issues/15516. In .NET Core 2.0, the Zip APIs are no longer setting the "x" mod on files unzipped.

This is going to be an issue for all tooling using NuGet to restore executables on non-Windows platforms. We shouldn't expect every place that is executing programs from NuGet packages to have to ensure the file has an "x" permission on it.

eerhardt added a commit to eerhardt/cli that referenced this issue Jan 28, 2017
@rrelyea rrelyea added this to the 4.0.1 milestone Jan 30, 2017
@rrelyea
Copy link
Contributor

rrelyea commented Jan 30, 2017

Any reason this is a shipstopper for rtm?

@eerhardt
Copy link
Author

Not a shipstopper. This only affects "2.0". "1.0" works fine.

@eerhardt
Copy link
Author

@rrelyea - when VS 2017 is out the door, can we get this issue triaged? This is going to affect a lot of "2.0" scenarios, so I'd like to get it fixed early in "2.0".

@eerhardt
Copy link
Author

eerhardt commented Mar 1, 2017

For example, this is breaking the dotnet cache feature on non-Windows machines in 2.0 because the crossgen executable is not marked with the "x" permission.

@gkhanna79 @ramarag

@eerhardt
Copy link
Author

eerhardt commented Mar 3, 2017

Shell scripts need to be marked executable as well.

/cc @livarcocc

@eerhardt
Copy link
Author

@rrelyea - as we are getting more people using .NET Core 2.0, this is becoming more of an issue. See https:/dotnet/cli/issues/6286. Can we get this looked into?

@eerhardt
Copy link
Author

/cc @livarcocc

@Eilon
Copy link

Eilon commented Apr 24, 2017

@rrelyea - this issue blocks ASP.NET Core (and presumably other) apps from running after running the publish operation. Do we have an idea when we might see a fix for this?

@muratg
Copy link

muratg commented Apr 24, 2017

👀

@rrelyea rrelyea modified the milestones: 4.3, Future-0 Apr 24, 2017
@rrelyea
Copy link
Contributor

rrelyea commented Apr 24, 2017

From thread with NetCore team...i think they are addressing this.
However, Eric said in that thread:
I kind of think this will have to get resolved in NuGet regardless. The reasoning being that we already have a bunch of .nupkgs that were built with 1.0 that don’t have permission information inside of them.

@eerhardt
Copy link
Author

From thread with NetCore team...i think they are addressing this.

The NetCore team is not addressing this. It is an intentional breaking change from netcoreapp1.x to netcoreapp2.0 in the System.IO.Compression area.

@tmds
Copy link

tmds commented Apr 27, 2017

In 1.x, files created by .NET Core had the x-bit set. In 2.x, files created by .NET Core no longer have the x-bit set. This change is not specific to System.IO.Compression.

A change made in ZipArchive is making the permission bits accessible (dotnet/corefx#18565) but no-one is using those yet.

Packages created so far, don't have the x-bit set for their files. Extracting packages, resulted in the x-bit being set for all files on 1.x and for no files on 2.x. This means executable files will no longer be executable when extracting with 2.x.

When support is added for maintaining permissions when packing and unpacking, there is still an issue for existing packages that don't have the x-bit set and relied on the 1.x behavior to set it.

Most packages contain only dlls and so files, they seem to work fine without the x-bit. Packages containing executables&scripts are affected.

@kichalla
Copy link

kichalla commented Jun 9, 2017

@tmds Hmm, did you test with the repro scenario I mentioned here? I did clear the nuget cache doing dotnet nuget locals all --clear and followed the repro steps in the link above, but I still see the execute permission not set. Just want to make sure if we both are testing the same scenario.

@tmds
Copy link

tmds commented Jun 9, 2017

@kichalla the quest continues. The x-bit is not set on the application. However, it is set in the package folder upon extracting!

$ ls -lah ~/.nuget/packages/runtime.linux-x64.microsoft.netcore.dotnetapphost/2.0.0-preview2-25407-01/runtimes/linux-x64/native/apphost 
-rwxrw-rw-. 1 tmds tmds 96K Jun  7 13:04 /home/tmds/.nuget/packages/runtime.linux-x64.microsoft.netcore.dotnetapphost/2.0.0-preview2-25407-01/runtimes/linux-x64/native/apphost

@tmds
Copy link

tmds commented Jun 9, 2017

@kichalla If I followed the breadcrumbs correctly, the execute bit gets lost here: https:/dotnet/sdk/blob/master/src/Tasks/Microsoft.NET.Build.Tasks/EmbedAppNameInHost.cs#L62.

@gkhanna79
Copy link

gkhanna79 commented Jun 9, 2017 via email

@gkhanna79
Copy link

If the possible cause identified by @tmds is correct, then this issue has been present for standalone publish in Preview1 as well and fix would be to set the X bit once the modified binary is published.

@steveharter can you PTAL?

@gkhanna79
Copy link

@kichalla Can you please file an issue in SDK for your repro above and assign it to @eerhardt and @steveharter?

@tmds
Copy link

tmds commented Jun 9, 2017

or alternatively, the apphost can be placed in the publish folder using File.Copy and renamed using File.Move.

@gkhanna79
Copy link

Apphost needs to be modified as part of publish operation so simply copying is not going to work.

@tmds
Copy link

tmds commented Jun 9, 2017

You can open the copied file

@gkhanna79
Copy link

@livarcocc When CLI published a standalone app, does it ever mark its entrypoint executable with the "X" bit on non-Windows?

@steveharter
Copy link

Taking a look now

@steveharter
Copy link

My understanding:

  • Only the modified apphost executable needs the +x; other executables are now properly restored from nuget.
  • This only occurs (the x is lost) during publish of a standalone app, when copying the source apphost to the destination\modified apphost

I am still going through the repro steps; clearing the nuget cache and then restore is being very slow...

@gkhanna79
Copy link

gkhanna79 commented Jun 9, 2017 via email

@livarcocc
Copy link

If the file is signed in the NuGet package, why is it losing that permission? It seems like these permissions should not be lost when copying/moving the file. And explicitly setting it in the SDK seems like a workaround for an issue somewhere else.

@kichalla
Copy link

kichalla commented Jun 9, 2017

@kichalla Can you please file an issue in SDK for your repro above and assign it to @eerhardt and @steveharter?

dotnet/sdk#1331

@tmds
Copy link

tmds commented Jun 12, 2017

If the file is signed in the NuGet package, why is it losing that permission? It seems like these permissions should not be lost when copying/moving the file.

@livarcocc This is the code which is 'copying' the app host: https:/dotnet/sdk/blob/master/src/Tasks/Microsoft.NET.Build.Tasks/EmbedAppNameInHost.cs#L62. It is creating a new file from bytes in memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants