-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Make SdkResolver-provided environment variables take precedence over ambient environment #12655
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
base: vs18.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1387,14 +1387,11 @@ PropertyDictionary<ProjectPropertyInstance> IEvaluatorData<ProjectPropertyInstan | |
|
|
||
| public void AddSdkResolvedEnvironmentVariable(string name, string value) | ||
| { | ||
| // If the property has already been set as an environment variable, we do not overwrite it. | ||
| if (_environmentVariableProperties.Contains(name)) | ||
| { | ||
| _loggingContext.LogComment(MessageImportance.Low, "SdkEnvironmentVariableAlreadySet", name, value); | ||
| return; | ||
| } | ||
| ErrorUtilities.VerifyThrowArgumentLength(name); | ||
| ErrorUtilities.VerifyThrowArgumentNull(value); | ||
|
|
||
| // If another SDK already set it, we do not overwrite it. | ||
| else if (_sdkResolvedEnvironmentVariableProperties?.Contains(name) == true) | ||
| if (_sdkResolvedEnvironmentVariableProperties?.Contains(name) == true) | ||
| { | ||
| _loggingContext.LogComment(MessageImportance.Low, "SdkEnvironmentVariableAlreadySetBySdk", name, value); | ||
| return; | ||
|
|
@@ -1406,8 +1403,18 @@ public void AddSdkResolvedEnvironmentVariable(string name, string value) | |
|
|
||
| _sdkResolvedEnvironmentVariableProperties.Set(property); | ||
|
|
||
| // Only set the local property if it does not already exist, prioritizing regular properties defined in XML. | ||
| if (GetProperty(name) is null) | ||
| // SDK-resolved environment variables override ambient environment variables. | ||
| bool overridingAmbient = _environmentVariableProperties.Contains(name); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is null-check needed?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot ensure that null environment variable names are handled in the Project and ProjectInstance handling
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added null checks for both |
||
| if (overridingAmbient) | ||
| { | ||
| _environmentVariableProperties.Remove(name); | ||
| _loggingContext.LogComment(MessageImportance.Low, "SdkEnvironmentVariableOverridingAmbient", name, value); | ||
| } | ||
|
|
||
| // Set the property, overriding ambient environment variables but not regular properties defined in XML. | ||
| // If we're overriding an ambient variable, or if the property doesn't exist, set it. | ||
| // Otherwise, prioritize regular properties defined in XML. | ||
| if (overridingAmbient || GetProperty(name) is null) | ||
|
Comment on lines
+1414
to
+1417
|
||
| { | ||
| ((IEvaluatorData<ProjectPropertyInstance, ProjectItemInstance, ProjectMetadataInstance, ProjectItemDefinitionInstance>)this) | ||
| .SetProperty(name, value, isGlobalProperty: false, mayBeReserved: false, loggingContext: _loggingContext, isEnvironmentVariable: true, isCommandLineProperty: false); | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
The equality check is comparing
_itemsToAdd?.Countwithresult._propertiesToAdd?.Countinstead ofresult._itemsToAdd?.Count. This is a copy-paste error that makes the equality comparison incorrect.