Skip to content
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

Only save the project file if a change has been made #80

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions tools/DependencyUpdater/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -805,21 +805,22 @@ static void UpdateLibrary(string workingDirectory,
}

Console.WriteLine($"Bumping {packageName} from {packageOriginVersion} to {packageTargetVersion}.");
}

// if this is the Test Framework, need to update the nfproj file too
if (packageName == "nanoFramework.TestFramework")
{
// read nfproj file
var nfprojFileContent = File.ReadAllText(projectToUpdate);

// if this is the Test Framework, need to update the nfproj file too
if (packageName == "nanoFramework.TestFramework")
{
// read nfproj file
var nfprojFileContent = File.ReadAllText(projectToUpdate);

var updatedProjContent = Regex.Replace(nfprojFileContent, $"(?<=packages\\\\nanoFramework\\.TestFramework\\.)(?'version'\\d+\\.\\d+\\.\\d+)(?=\\\\build\\\\)", packageTargetVersion, RegexOptions.ExplicitCapture);
var updatedProjContent = Regex.Replace(nfprojFileContent, $"(?<=packages\\\\nanoFramework\\.TestFramework\\.)(?'version'\\d+\\.\\d+\\.\\d+)(?=\\\\build\\\\)", packageTargetVersion, RegexOptions.ExplicitCapture);

File.WriteAllText(projectToUpdate, updatedProjContent);
File.WriteAllText(projectToUpdate, updatedProjContent);
}
}

CoryCharlton marked this conversation as resolved.
Show resolved Hide resolved
// Remove the <Private> elements NuGet adds to the project file
// This could be async be the tool isn't using that so I'll skip it for now
var privateElementsRemoved = false;
var projectDocument = XDocument.Load(projectToUpdate);
var referenceElements = projectDocument.Root?.Descendants().Where(x => x.Name.LocalName == "Reference").ToList();

Expand All @@ -828,12 +829,16 @@ static void UpdateLibrary(string workingDirectory,
var privateElements = referenceElement.Descendants().Where(x => x.Name.LocalName == "Private").ToList();
foreach (var privateElement in privateElements)
{
privateElementsRemoved = true;
privateElement.Remove();
}
}

using var projectFile = File.Create(projectToUpdate);
projectDocument.Save(projectFile, SaveOptions.None);
if (privateElementsRemoved)
{
using var projectFile = File.Create(projectToUpdate);
projectDocument.Save(projectFile, SaveOptions.None);
}

// load nuspec file content, if there is a nuspec file to update
if (nuspecFileName is not null)
Expand Down