Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Comments

Reset current directory on Core#2978

Merged
rainersigwald merged 2 commits intodotnet:masterfrom
rainersigwald:enable-systemdirectory
Mar 23, 2018
Merged

Reset current directory on Core#2978
rainersigwald merged 2 commits intodotnet:masterfrom
rainersigwald:enable-systemdirectory

Conversation

@rainersigwald
Copy link
Member

Full-framework MSBuild was resetting the current directory at the end of build requests and at node idle, which helps avoid holding handles to project directories that the user may wish to delete while a worker node is still alive in the background. That wasn't done on .NET Core because at the time of the original port, there wasn't an Environment.SystemDirectory to use.

That property is now available, but returns the empty string on Linux, which fails Directory.SetCurrentDirectory(). So I'm avoiding it by using the current MSBuild tools directory, which should exist as long as the MSBuild process keeps running.

Fixes #2977.

Full-framework MSBuild was resetting the current directory at the end of build requests and at node idle, which helps avoid holding handles to project directories that the user may wish to delete while a worker node is still alive in the background. That wasn't done on .NET Core because at the time of the original port, there wasn't an `Environment.SystemDirectory` to use.

That property is now available, but returns the empty string on Linux, which fails `Directory.SetCurrentDirectory()`. So I'm avoiding it by using the current MSBuild tools directory, which should exist as long as the MSBuild process keeps running.

Fixes dotnet#2977.
#endif
// On Windows, a process holds a handle to the current directory,
// so reset it away from a user-requested folder that may get deleted.
NativeMethodsShared.SetCurrentDirectory(BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory);
Copy link
Member Author

Choose a reason for hiding this comment

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

Please check my logic about the new default value for this!

I can also do an if-windows conditional.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can setting cwd to a bogus value have any external behaviour? Files written, node failure logs, etc? If yes, do an if-windows conditional. If no, it doesn't really matter.

Copy link
Member Author

Choose a reason for hiding this comment

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

AFAIK none of that depends on CWD . . .

Copy link
Contributor

@jeffkl jeffkl left a comment

Choose a reason for hiding this comment

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

Can we get rid of the feature flag or is it still used somewhere? (I'm on my phone otherwise I would look it up myself)

@rainersigwald
Copy link
Member Author

macOS: Possible issue connecting to GitHub or cloning the repository. This could be caused by a lack of network connectivity or a lack of disk space. Please email netciadmin.

@dotnet-bot test OSX10.13 Build for CoreCLR please

@rainersigwald
Copy link
Member Author

The feature flag is sadly still used, in a confusing place for bad reasons.

https://github.com/Microsoft/msbuild/blob/0dcae6d2841e71d9ca1031c099c6883e64583afd/src/Shared/UnitTests/FileUtilities_Tests.cs#L558-L746

Those tests still need to be disabled, but I couldn't come up with a better name for the flag that describes how they're broken. Totally open to suggestions!

@jeffkl
Copy link
Contributor

jeffkl commented Feb 9, 2018

Hmm, perhaps the tests should just not use Environment.SystemDirectory? it looks like they could use any directory

#if FEATURE_ENVIRONMENT_SYSTEMDIRECTORY
// Somehow the startup directory vanished. This can happen if build was started from a USB Key and it was removed.
NativeMethodsShared.SetCurrentDirectory(Environment.SystemDirectory);
#endif
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the inconsistency with the other changes? Not that it matters, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

No good reason.

@rainersigwald rainersigwald added this to the MSBuild 15.7 milestone Mar 22, 2018
@rainersigwald
Copy link
Member Author

@dotnet-bot test this please

(don't trust stale results from February, but want this in)

@rainersigwald
Copy link
Member Author

@dotnet-bot test Ubuntu16.04 Build for CoreCLR please

An odd hang:

MSBuild Failure: From calculating based on the memorystream, about to read n = -21. length = 135784, rawPosition = 135805, readLength = 21, stringLength = 108, currPos = 87.
Waiting for debugger to attach to process: 75712

@rainersigwald rainersigwald merged commit d83a9ed into dotnet:master Mar 23, 2018
@rainersigwald rainersigwald deleted the enable-systemdirectory branch March 23, 2018 00:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants