-
Notifications
You must be signed in to change notification settings - Fork 954
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
53b227b
force set `Condition="false"` on Microsoft.WebApplication.targets
brettfo ba2f6e5
Merge branch 'main' into dev/brettfo/package-update
abdulapopoola 69e740e
Merge branch 'main' into dev/brettfo/package-update
abdulapopoola 3fa3c73
Merge branch 'main' into dev/brettfo/package-update
abdulapopoola 80e424e
Merge branch 'main' into dev/brettfo/package-update
abdulapopoola 5ee3d32
Merge branch 'main' into dev/brettfo/package-update
abdulapopoola 0fb0c33
Merge branch 'main' into dev/brettfo/package-update
abdulapopoola File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
47 changes: 47 additions & 0 deletions
47
...lpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/WebApplicationTargetsConditionPatcher.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
using Microsoft.Language.Xml; | ||
|
||
namespace NuGetUpdater.Core.Updater | ||
{ | ||
internal class WebApplicationTargetsConditionPatcher : IDisposable | ||
{ | ||
private string? _capturedCondition; | ||
private readonly XmlFilePreAndPostProcessor _processor; | ||
|
||
public WebApplicationTargetsConditionPatcher(string projectFilePath) | ||
{ | ||
_processor = new XmlFilePreAndPostProcessor( | ||
getContent: () => File.ReadAllText(projectFilePath), | ||
setContent: s => File.WriteAllText(projectFilePath, s), | ||
nodeFinder: doc => doc.Descendants() | ||
ryanbrandenburg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.FirstOrDefault(e => e.Name == "Import" && e.GetAttributeValue("Project") == @"$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets") | ||
as XmlNodeSyntax, | ||
preProcessor: n => | ||
{ | ||
var element = (IXmlElementSyntax)n; | ||
_capturedCondition = element.GetAttributeValue("Condition"); | ||
ryanbrandenburg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return (XmlNodeSyntax)element.RemoveAttributeByName("Condition").WithAttribute("Condition", "false"); | ||
}, | ||
postProcessor: n => | ||
{ | ||
var element = (IXmlElementSyntax)n; | ||
var newElement = element.RemoveAttributeByName("Condition"); | ||
if (_capturedCondition is not null) | ||
{ | ||
newElement = newElement.WithAttribute("Condition", _capturedCondition); | ||
} | ||
|
||
return (XmlNodeSyntax)newElement; | ||
} | ||
); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_processor.Dispose(); | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/XmlFilePreAndPostProcessor.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
|
||
using Microsoft.Language.Xml; | ||
|
||
namespace NuGetUpdater.Core.Updater | ||
{ | ||
internal class XmlFilePreAndPostProcessor : IDisposable | ||
{ | ||
public Func<string> GetContent { get; } | ||
public Action<string> SetContent { get; } | ||
public Func<XmlDocumentSyntax, XmlNodeSyntax?> NodeFinder { get; } | ||
public Func<XmlNodeSyntax, XmlNodeSyntax> PreProcessor { get; } | ||
public Func<XmlNodeSyntax, XmlNodeSyntax> PostProcessor { get; } | ||
|
||
public XmlFilePreAndPostProcessor(Func<string> getContent, Action<string> setContent, Func<XmlDocumentSyntax, XmlNodeSyntax?> nodeFinder, Func<XmlNodeSyntax, XmlNodeSyntax> preProcessor, Func<XmlNodeSyntax, XmlNodeSyntax> postProcessor) | ||
{ | ||
GetContent = getContent; | ||
SetContent = setContent; | ||
NodeFinder = nodeFinder; | ||
PreProcessor = preProcessor; | ||
PostProcessor = postProcessor; | ||
PreProcess(); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
PostProcess(); | ||
} | ||
|
||
private void PreProcess() => RunProcessor(PreProcessor); | ||
|
||
private void PostProcess() => RunProcessor(PostProcessor); | ||
|
||
private void RunProcessor(Func<XmlNodeSyntax, XmlNodeSyntax> processor) | ||
{ | ||
var content = GetContent(); | ||
var xml = Parser.ParseText(content); | ||
if (xml is null) | ||
{ | ||
return; | ||
} | ||
|
||
var node = NodeFinder(xml); | ||
if (node is null) | ||
{ | ||
return; | ||
} | ||
|
||
var replacementElement = processor(node); | ||
var replacementXml = xml.ReplaceNode(node, replacementElement); | ||
var replacementString = replacementXml.ToFullString(); | ||
SetContent(replacementString); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
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.
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.