diff --git a/.editorconfig b/.editorconfig index 5426f75..b001005 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,6 +8,8 @@ root = true insert_final_newline = true end_of_line = crlf indent_style = tab +vsspell_section_id = 7001f507961747b8a917eb15b0da2eb2 +vsspell_ignored_words_7001f507961747b8a917eb15b0da2eb2 = Api|Committer|fallback|Utc|Util|Vcs [*.{cs,vb}] # Sort using and Import directives with System.* appearing first @@ -143,6 +145,9 @@ csharp_space_between_method_declaration_parameter_list_parentheses = false csharp_space_between_parentheses = false csharp_space_between_square_brackets = false +# VSSpell001: Spell Check +dotnet_diagnostic.VSSpell001.severity = suggestion + [*.{xml,csproj,targets,props,json}] indent_size = 2 indent_style = space diff --git a/NetRevisionTask.sln b/NetRevisionTask.sln index 12d5b26..ea21aa1 100644 --- a/NetRevisionTask.sln +++ b/NetRevisionTask.sln @@ -1,9 +1,14 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26730.10 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.33801.447 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetRevisionTask", "NetRevisionTask\NetRevisionTask.csproj", "{F934C33E-1B39-44F8-B989-4C8198767DCB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetRevisionTask", "NetRevisionTask\NetRevisionTask.csproj", "{F934C33E-1B39-44F8-B989-4C8198767DCB}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8915165A-1221-4D0B-86C9-2ED7863FE019}" + ProjectSection(SolutionItems) = preProject + .editorconfig = .editorconfig + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/NetRevisionTask/AssemblyInfoHelper.cs b/NetRevisionTask/AssemblyInfoHelper.cs index 9ea7573..4dd411d 100644 --- a/NetRevisionTask/AssemblyInfoHelper.cs +++ b/NetRevisionTask/AssemblyInfoHelper.cs @@ -33,7 +33,7 @@ public AssemblyInfoHelper(string projectDir, bool throwOnMissingFile, ILogger lo this.logger = logger; this.projectDir = projectDir; - FindAssemblyInfoFile(projectDir); + FindAssemblyInfoFile(); if (fileName == null && throwOnMissingFile) { throw new FileNotFoundException($@"AssemblyInfo file not found in ""{projectDir}"" or the usual subdirectories."); @@ -158,8 +158,7 @@ private void AnalyseFile() /// /// Finds the AssemblyInfo file in the specified directory. /// - /// The project directory to search in. - private void FindAssemblyInfoFile(string projectDir) + private void FindAssemblyInfoFile() { fileName = Path.Combine("Properties", "AssemblyInfo.cs"); if (!File.Exists(FullFileName)) diff --git a/NetRevisionTask/NetRevisionTask.csproj b/NetRevisionTask/NetRevisionTask.csproj index deb0375..84e1130 100644 --- a/NetRevisionTask/NetRevisionTask.csproj +++ b/NetRevisionTask/NetRevisionTask.csproj @@ -54,8 +54,13 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/NetRevisionTask/RevisionFormatter.cs b/NetRevisionTask/RevisionFormatter.cs index e74f364..605022c 100644 --- a/NetRevisionTask/RevisionFormatter.cs +++ b/NetRevisionTask/RevisionFormatter.cs @@ -52,7 +52,7 @@ internal class RevisionFormatter /// /// Gets the build time. /// - public DateTimeOffset BuildTime => buildTime; + public static DateTimeOffset BuildTime => buildTime; #endregion Data properties diff --git a/NetRevisionTask/VcsProviders/GitProvider.cs b/NetRevisionTask/VcsProviders/GitProvider.cs index 9b3fe97..f662868 100644 --- a/NetRevisionTask/VcsProviders/GitProvider.cs +++ b/NetRevisionTask/VcsProviders/GitProvider.cs @@ -350,13 +350,11 @@ private string FindGitBinary() } } - var registry = new WindowsRegistry(); - // Read registry uninstaller key if (git == null && isWindows) { string keyPath = @"Software\Microsoft\Windows\CurrentVersion\Uninstall\Git_is1"; - string loc = registry.GetStringValue("HKLM", keyPath, "InstallLocation"); + string loc = WindowsRegistry.GetStringValue("HKLM", keyPath, "InstallLocation"); if (loc != null) { string testPath = Path.Combine(loc, Path.Combine("bin", gitExeName)); @@ -372,7 +370,7 @@ private string FindGitBinary() if (git == null && Is64Bit && isWindows) { string keyPath = @"Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Git_is1"; - string loc = registry.GetStringValue("HKLM", keyPath, "InstallLocation"); + string loc = WindowsRegistry.GetStringValue("HKLM", keyPath, "InstallLocation"); if (loc != null) { string testPath = Path.Combine(loc, Path.Combine("bin", gitExeName)); @@ -388,7 +386,7 @@ private string FindGitBinary() if (git == null && isWindows) { string keyPath = @"Software\Microsoft\Windows\CurrentVersion\Uninstall\Git_is1"; - string loc = registry.GetStringValue("HKCU", keyPath, "InstallLocation"); + string loc = WindowsRegistry.GetStringValue("HKCU", keyPath, "InstallLocation"); if (loc != null) { string testPath = Path.Combine(loc, Path.Combine("bin", gitExeName)); diff --git a/NetRevisionTask/VcsProviders/SubversionProvider.cs b/NetRevisionTask/VcsProviders/SubversionProvider.cs index dcda6e5..26dad97 100644 --- a/NetRevisionTask/VcsProviders/SubversionProvider.cs +++ b/NetRevisionTask/VcsProviders/SubversionProvider.cs @@ -270,13 +270,11 @@ private string FindSvnBinary() if (!File.Exists(svn)) svn = null; } - var registry = new WindowsRegistry(); - // If TortoiseSVN has been installed with command-line binaries if (svn == null && isWindows) { string keyPath = @"Software\TortoiseSVN"; - string loc = registry.GetStringValue("HKLM", keyPath, "Directory"); + string loc = WindowsRegistry.GetStringValue("HKLM", keyPath, "Directory"); if (loc != null) { svn = Path.Combine(loc, Path.Combine(@"bin", svnExeName)); @@ -295,7 +293,7 @@ private string FindSvnBinary() if (svn == null && isWindows) { string keyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\CollabNet Subversion Client"; - string loc = registry.GetStringValue("HKLM", keyPath, "UninstallString"); + string loc = WindowsRegistry.GetStringValue("HKLM", keyPath, "UninstallString"); if (loc != null) { svn = Path.Combine(Path.GetDirectoryName(loc), svnExeName); @@ -312,7 +310,7 @@ private string FindSvnBinary() if (svn == null && isWindows) { string keyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{F5980BF8-ED95-4742-A89F-CDAC202D53CF}_is1"; - string loc = registry.GetStringValue("HKLM", keyPath, "InstallLocation"); + string loc = WindowsRegistry.GetStringValue("HKLM", keyPath, "InstallLocation"); if (loc != null) { svn = Path.Combine(loc, svnExeName); @@ -331,7 +329,7 @@ private string FindSvnBinary() if (svn == null && Is64Bit && isWindows) { string keyPath = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\CollabNet Subversion Client"; - string loc = registry.GetStringValue("HKLM", keyPath, "UninstallString"); + string loc = WindowsRegistry.GetStringValue("HKLM", keyPath, "UninstallString"); if (loc != null) { svn = Path.Combine(Path.GetDirectoryName(loc), svnExeName); @@ -348,7 +346,7 @@ private string FindSvnBinary() if (svn == null && Is64Bit && isWindows) { string keyPath = @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{F5980BF8-ED95-4742-A89F-CDAC202D53CF}_is1"; - string loc = registry.GetStringValue("HKLM", keyPath, "InstallLocation"); + string loc = WindowsRegistry.GetStringValue("HKLM", keyPath, "InstallLocation"); if (loc != null) { svn = Path.Combine(loc, svnExeName); diff --git a/NetRevisionTask/WindowsRegistry.cs b/NetRevisionTask/WindowsRegistry.cs index abad9d5..9bff715 100644 --- a/NetRevisionTask/WindowsRegistry.cs +++ b/NetRevisionTask/WindowsRegistry.cs @@ -16,7 +16,7 @@ internal class WindowsRegistry /// The path of the key to read the value from. /// The value to read. /// The read value if it exists and is a string; otherwise, null. - public string GetStringValue(string root, string key, string value) + public static string GetStringValue(string root, string key, string value) { #if NETFULL RegistryKey rootKey; @@ -36,9 +36,9 @@ public string GetStringValue(string root, string key, string value) { object obj = regKey.GetValue(value); regKey.Close(); - if (obj is string) + if (obj is string objStr) { - return (string)obj; + return objStr; } } #else @@ -61,7 +61,7 @@ public string GetStringValue(string root, string key, string value) var sb = new StringBuilder(1000); int length = sb.Capacity; bool found = RegQueryValueEx(keyHandle, value, 0, out RegistryValueKind kind, sb, ref length) == 0; - RegCloseKey(keyHandle); + _ = RegCloseKey(keyHandle); if (found) return sb.ToString(); } @@ -74,7 +74,7 @@ public string GetStringValue(string root, string key, string value) #if !NETFULL - [DllImport("advapi32.dll")] + [DllImport("advapi32.dll", CharSet = CharSet.Unicode)] private static extern int RegOpenKeyEx( UIntPtr hKey, string subKey, @@ -82,11 +82,11 @@ private static extern int RegOpenKeyEx( int samDesired, out UIntPtr hkResult); - [DllImport("advapi32.dll", SetLastError = true)] + [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)] private static extern int RegCloseKey( UIntPtr hKey); - [DllImport("advapi32.dll", SetLastError = true)] + [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)] private static extern uint RegQueryValueEx( UIntPtr hKey, string lpValueName, @@ -95,7 +95,7 @@ private static extern uint RegQueryValueEx( IntPtr lpData, ref int lpcbData); - [DllImport("advapi32.dll", SetLastError = true)] + [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)] private static extern uint RegQueryValueEx( UIntPtr hKey, string lpValueName,