-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect mismatch between cli and msbuild versions
closes #490
- Loading branch information
Showing
4 changed files
with
156 additions
and
2 deletions.
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
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.IO.Abstractions; | ||
using System.Xml.Linq; | ||
using System.Xml.XPath; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace CSharpier.Cli; | ||
|
||
public static class HasMismatchedCliAndMsBuildVersions | ||
{ | ||
public static bool Check(string directory, IFileSystem fileSystem, ILogger logger) | ||
{ | ||
var csProjPaths = fileSystem.Directory | ||
.EnumerateFiles(directory, "*.csproj", SearchOption.AllDirectories) | ||
.ToArray(); | ||
|
||
var versionOfDotnetTool = typeof(CommandLineFormatter).Assembly.GetName().Version!.ToString( | ||
3 | ||
); | ||
|
||
foreach (var pathToCsProj in csProjPaths) | ||
{ | ||
// this could potentially use the Microsoft.CodeAnalysis.Project class, but that was | ||
// proving difficult to use | ||
var csProjXElement = XElement.Load(fileSystem.File.OpenRead(pathToCsProj)); | ||
var csharpierMsBuildElement = csProjXElement | ||
.XPathSelectElements("//PackageReference[@Include='CSharpier.MsBuild']") | ||
.FirstOrDefault(); | ||
if (csharpierMsBuildElement == null) | ||
{ | ||
continue; | ||
} | ||
|
||
var versionOfMsBuildPackage = csharpierMsBuildElement.Attribute("Version")?.Value; | ||
if (versionOfMsBuildPackage == null) | ||
{ | ||
logger.LogError( | ||
$"The csproj at {pathToCsProj} uses an unknown version of CSharpier.MsBuild" | ||
+ $" which is a mismatch with version {versionOfDotnetTool}" | ||
); | ||
return true; | ||
} | ||
|
||
if (versionOfDotnetTool != versionOfMsBuildPackage) | ||
{ | ||
logger.LogError( | ||
$"The csproj at {pathToCsProj} uses version {versionOfMsBuildPackage} of CSharpier.MsBuild" | ||
+ $" which is a mismatch with version {versionOfDotnetTool}" | ||
); | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
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