Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
11 changes: 8 additions & 3 deletions NetRevisionTask.sln
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 2 additions & 3 deletions NetRevisionTask/AssemblyInfoHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -158,8 +158,7 @@ private void AnalyseFile()
/// <summary>
/// Finds the AssemblyInfo file in the specified directory.
/// </summary>
/// <param name="projectDir">The project directory to search in.</param>
private void FindAssemblyInfoFile(string projectDir)
private void FindAssemblyInfoFile()
{
fileName = Path.Combine("Properties", "AssemblyInfo.cs");
if (!File.Exists(FullFileName))
Expand Down
5 changes: 5 additions & 0 deletions NetRevisionTask/NetRevisionTask.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@
<PackageReference Include="Microsoft.Build.Framework" Version="14.3.0" />
<!-- Info: A later version with VS 2017 would be 15.1.1012 -->
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="14.3.0" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" />
<!-- Marks all packages as 'local only' so they don't end up in the nuspec. -->
<PackageReference Update="@(PackageReference)" PrivateAssets="All" />
<PackageReference Update="Microsoft.CodeAnalysis.NetAnalyzers" Version="7.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion NetRevisionTask/RevisionFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ internal class RevisionFormatter
/// <summary>
/// Gets the build time.
/// </summary>
public DateTimeOffset BuildTime => buildTime;
public static DateTimeOffset BuildTime => buildTime;

#endregion Data properties

Expand Down
8 changes: 3 additions & 5 deletions NetRevisionTask/VcsProviders/GitProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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));
Expand Down
12 changes: 5 additions & 7 deletions NetRevisionTask/VcsProviders/SubversionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions NetRevisionTask/WindowsRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class WindowsRegistry
/// <param name="key">The path of the key to read the value from.</param>
/// <param name="value">The value to read.</param>
/// <returns>The read value if it exists and is a string; otherwise, null.</returns>
public string GetStringValue(string root, string key, string value)
public static string GetStringValue(string root, string key, string value)
{
#if NETFULL
RegistryKey rootKey;
Expand All @@ -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
Expand All @@ -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();
}
Expand All @@ -74,19 +74,19 @@ 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,
int ulOptions,
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,
Expand All @@ -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,
Expand Down