-
Notifications
You must be signed in to change notification settings - Fork 926
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
force set Condition="false"
on Microsoft.WebApplication.targets
#8946
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The file $(VSToolsPath)\WebApplications\Microsoft.WebApplications.targets can never be resolved in the updater as it runs in the Linux Docker container, so an always false condition is added to that import to make the minimal change necessary to allow the NuGet updater to successfully run. After completion, the condition attribute is restored.
cc3bcbb
to
53b227b
Compare
ryanbrandenburg
approved these changes
Jan 31, 2024
private string? _capturedCondition; | ||
private readonly XmlFilePreAndPostProcessor _processor; | ||
|
||
public WebApplicationTargetsConditionPatcher(string projectFilePath) |
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 like this shape, I think it makes it relatively easy to create a couple of similar Patchers and group them together into an aggregator.
.../helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/WebApplicationTargetsConditionPatcher.cs
Show resolved
Hide resolved
.../helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/WebApplicationTargetsConditionPatcher.cs
Show resolved
Hide resolved
JoeRobich
approved these changes
Feb 6, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The import
$(VSToolsPath)\WebApplications\Microsoft.WebApplications.targets
can never be resolved in the updater as it runs in the Linux Docker container. Under most conditions, the$(VSToolsPath)
property will not be set so this isn't an issue (n.b., theCondition="'$(VSToolsPath)' != ''"
attribute), but some project files do set it, which makes it impossible to skip importing that targets file through the normal means.The fix in this PR is to always set
Condition="false"
on that import node and then restore it after the run to its original state. An equally valid fix would have been to remove/re-add the entire<Import>
node, but re-inserting the original node at the correct location is difficult; instead it's much easer to find the node and modify (or remove, etc.) the condition attribute.It is also a possibility for the code owners to update their
.csproj
to use the SDK-friendlyMSBuild.Microsoft.VisualStudio.Web.targets
NuGet package. That would allow the updater to still run, but requires non-trivial permanent changes/migrations to their project file and that's outside the scope of what we're trying to accomplish: an in-place package update with a minimal diff.Another potential fix would be to place an empty
Microsoft.WebApplication.targets
file in the Docker image. This would certainly work at runtime and require less code, but would not be unit-testable.I split up the behavior into parts that I thought made the most sense.
WebApplicationTargetsConditionPatcher
. I usedIDisposable
for everything to ensure the original file is always restored to its correct state.<Import>
node and set/reset the condition attribute, nothing more.XmlFilePreAndPostProcessor
class. This is the one that parses the XML and calls the appropriatePreProcess
andPostProcess
functions.All of the code was done this way so that if we have to expand the pattern of targets files that can't be imported, we can do very targeted fixes with the minimal amount of mess. Ideally this will be the only special case we need, but in all reality, we may end up with one or two more in the future.
Fixes #8532.