-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Update BuildEnvironmentHelper to locate .NET Core app directory #1069
Conversation
In .NET Core, the AppContext.BaseDirectory can be used to locate the application's dependencies.
Can you elaborate on why this helps? I don't think I fully understand the scenario. |
When you execute However, when you do |
Ahh, yes it does make sense! So with the new package, the toolset files will be in Can you update the comment for this case to be explicit about that scenario and why loading from that directory is right? |
|
||
#if !CLR2COMPATIBILITY // Assemblies compiled against anything older than .NET 4.0 won't have a System.AppContext | ||
// Try the base directory that the assembly resolver uses to probe for assemblies. | ||
() => TryFromFolder(AppContext.BaseDirectory, runningTests, runningInVisualStudio, visualStudioPath) |
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.
Now that I see what's up, I think this should be above the current-working-directory path. If someone's redistributing an MSBuild runtime, that should be preferred over something that happens to be in the CWD, just as it would be if we found it next to our MSBuild.exe.
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.
I went back and forth on this too. Technically if I see MSBuild.exe (and the runtime) in the current directory, I sort of expect it to be used. That would make sense for an end user but not necessarily for the app developer. It seems rare that someone would change the current directory to some place that has MSBuild and then run a completely different app...
Yeah but _only_ if you can help me understand why the test fails... Is it because my change needs to be mocked to not return a valid location? |
I have updated the comment, let me know about the test fix when you have a chance. |
I think I get the test failure. Inside the test run I have You should be able to fix this by adding a new delegate like the ones that are already there to return |
@@ -105,7 +105,7 @@ public void BuildEnvironmentDetectsVisualStudioByEnvironment() | |||
{ | |||
Environment.SetEnvironmentVariable("VSINSTALLDIR", env.TempFolderRoot); | |||
Environment.SetEnvironmentVariable("VisualStudioVersion", "15.0"); | |||
BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(); | |||
BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly(getAppContextBaseDirectory: ReturnNull); |
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.
Do you need to specify this? Seems like it should be redundant (since it's after the env-var fallback).
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.
I was worried if the order ever changed then the test could start to fail so I put this in here to remove the AppContext.BaseDirectory from the equation for all cases. I can remove it if you'd like
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.
I think I'd rather the tests fail in that case.
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.
Okay I'll update the test
77e9cff
to
33cb003
Compare
@dotnet-bot test OSX Build for CoreCLR please |
33cb003
to
a8d9a62
Compare
@AndyGerlicher @rainersigwald do you guys approve? |
In .NET Core, the AppContext.BaseDirectory can be used to locate the application's dependencies.
Related to #1039