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

StyleCop upgrade and many warning was resolved or disabled #261

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
9 changes: 8 additions & 1 deletion nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@
</packageSources>
<trustedSigners>
<repository name="nuget" serviceIndex="https://api.nuget.org/v3/index.json">
<owners>Microsoft;xunit;aarnott;jkeech;sharwell;jamesnk</owners>
<owners>Microsoft;xunit;aarnott;jkeech;sharwell;jamesnk;Nerdbank;neuecc</owners>
<certificate fingerprint="0e5f38f57dc1bcc806d8494f4f90fbcedd988b46760709cbeec6f4219aa6157d" hashAlgorithm="SHA256" allowUntrustedRoot="false" />
<certificate fingerprint="5A2901D6ADA3D18260B9C6DFE2133C95D74B9EEF6AE0E5DC334C8454D1477DF4" hashAlgorithm="SHA256" allowUntrustedRoot="false" />
</repository>
<author name="Microsoft">
<certificate fingerprint="aa12da22a49bce7d5c1ae64cc1f3d892f150da76140f210abd2cbffca2c18a27" hashAlgorithm="SHA256" allowUntrustedRoot="false" />
</author>
<author name="newtonsoft">
<certificate fingerprint="a3af7af11ebb8ef729d2d91548509717e7e0ff55a129abc3aeaa8a6940267641" hashAlgorithm="SHA256" allowUntrustedRoot="false" />
</author>
<author name="Nerdbank">
<certificate fingerprint="1F891E64936D15DE5FAE22D910CD39F3E9860213C92F20CF9638A245B1249D2B" hashAlgorithm="SHA256" allowUntrustedRoot="false" />
</author>
<author name="xunit">
<certificate fingerprint="62EAAD4AAA8AF9ED0E08C03F78BECE95EC4A85AE87749E4D977D9D1E8A14BBB0" hashAlgorithm="SHA256" allowUntrustedRoot="false" />
</author>
</trustedSigners>
</configuration>
3 changes: 3 additions & 0 deletions src/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[*.{cs,csproj}]
indent_style = space
indent_size = 4
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,20 @@

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Internal.MicroBuild.NonShipping" Version="2.0.66" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="Nerdbank.GitVersioning" Version="1.6.30" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.5.107">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,23 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ServiceHub.Framework" Version="3.1.4097" />
<PackageReference Include="Microsoft.VisualStudio.Internal.MicroBuild.NonShipping" Version="2.0.66" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<PackageReference Include="Nerdbank.GitVersioning" Version="1.6.30" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Microsoft.VisualStudio.TemplateWizardInterface" Version="17.2.32505.113" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.5.107">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,24 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EnvDTE" Version="17.0.31902.203" />
<PackageReference Include="EnvDTE" Version="17.2.32505.113" />
<PackageReference Include="Microsoft.ServiceHub.Framework" Version="3.1.4097" />

<PackageReference Include="Microsoft.VisualStudio.Internal.MicroBuild.VisualStudio" Version="2.0.66" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.0.5232" />
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.0.31902.203" />

<PackageReference Include="Microsoft.VisualStudio.TemplateWizardInterface" Version="17.2.32505.113" />
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.2.2186">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.2.32505.173" />
<PackageReference Include="Microsoft.Web.Xdt" Version="3.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Jdt" Version="0.9.63" />
<PackageReference Include="NuGet.VisualStudio" Version="5.11.0" />
<PackageReference Include="Nerdbank.GitVersioning" Version="1.6.30" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.0" PrivateAssets="all" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Microsoft.VisualStudio.Jdt" Version="0.9.23" />
<PackageReference Include="NuGet.VisualStudio" Version="17.2.1" />
<PackageReference Include="Nerdbank.GitVersioning" Version="3.5.107" PrivateAssets="all" />
<PackageReference Include="NuGet.VisualStudio.Contracts" Version="17.2.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public BackgroundInstallationHandler(IPackageHandler successor)
public bool IsUpdate { get; set; } = false;

/// <inheritdoc/>
public override async TPL.Task Execute(Project project)
public override async TPL.Task ExecuteAsync(Project project)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
string projName = project.UniqueName;
bool needInstall = true;
lock (SyncObject)
Expand All @@ -48,7 +49,7 @@ public override async TPL.Task Execute(Project project)
{
string warningTitle = this.IsUpdate ? Resources.Resources.NugetUpdate_Title : Resources.Resources.NugetInstall_Title;
string warningMessage = this.IsUpdate ? Resources.Resources.NugetUpdate_Text : Resources.Resources.NugetInstall_Text;
if (await this.HasUserAcceptedWarningMessage(warningTitle, warningMessage))
if (await this.HasUserAcceptedWarningMessageAsync(warningTitle, warningMessage))
{
// Gets the general output pane to inform user of installation
IVsOutputWindowPane outputWindow = (IVsOutputWindowPane)await this.Package.GetServiceAsync(typeof(SVsGeneralOutputWindowPane));
Expand All @@ -61,7 +62,7 @@ public override async TPL.Task Execute(Project project)
string outputMessage = Resources.Resources.NugetInstall_FinishedOutput;
try
{
await this.Successor.Execute(project);
await this.Successor.ExecuteAsync(project);
}
catch
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ protected BasePackageHandler(IPackageHandler successor)
protected IPackageHandler Successor { get; }

/// <inheritdoc/>
public abstract TPL.Task Execute(Project project);
public abstract TPL.Task ExecuteAsync(Project project);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Microsoft.VisualStudio.SlowCheetah.VS
{
using EnvDTE;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using TPL = System.Threading.Tasks;

Expand All @@ -22,9 +23,10 @@ public DialogInstallationHandler(IPackageHandler successor)
}

/// <inheritdoc/>
public override async TPL.Task Execute(Project project)
public override async TPL.Task ExecuteAsync(Project project)
{
if (await this.HasUserAcceptedWarningMessage(Resources.Resources.NugetUpdate_Title, Resources.Resources.NugetUpdate_Text))
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
if (await this.HasUserAcceptedWarningMessageAsync(Resources.Resources.NugetUpdate_Title, Resources.Resources.NugetUpdate_Text))
{
// Creates dialog informing the user to wait for the installation to finish
IVsThreadedWaitDialogFactory twdFactory = await this.Package.GetServiceAsync(typeof(SVsThreadedWaitDialogFactory)) as IVsThreadedWaitDialogFactory;
Expand All @@ -37,7 +39,7 @@ public override async TPL.Task Execute(Project project)

try
{
await this.Successor.Execute(project);
await this.Successor.ExecuteAsync(project);
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public EmptyHandler(AsyncPackage package)
public AsyncPackage Package { get; }

/// <inheritdoc/>
public TPL.Task Execute(Project project)
public TPL.Task ExecuteAsync(Project project)
{
// Do nothing
return TPL.Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ internal interface IPackageHandler
/// </summary>
/// <param name="project">The project to peform actions on</param>
/// <returns>A task that executes the function</returns>
TPL.Task Execute(Project project);
TPL.Task ExecuteAsync(Project project);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Microsoft.VisualStudio.SlowCheetah.VS
{
using EnvDTE;
using Microsoft;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Shell;
using NuGet.VisualStudio;
Expand All @@ -24,13 +25,14 @@ public NuGetUninstaller(IPackageHandler successor)
}

/// <inheritdoc/>
public override async TPL.Task Execute(Project project)
public override async TPL.Task ExecuteAsync(Project project)
{
var componentModel = (IComponentModel)await this.Package.GetServiceAsync(typeof(SComponentModel));
Assumes.Present(componentModel);
IVsPackageUninstaller packageUninstaller = componentModel.GetService<IVsPackageUninstaller>();
packageUninstaller.UninstallPackage(project, SlowCheetahNuGetManager.OldPackageName, true);

await this.Successor.Execute(project);
await this.Successor.ExecuteAsync(project);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Microsoft.VisualStudio.SlowCheetah.VS
{
using EnvDTE;
using Microsoft;
using Microsoft.VisualStudio.ComponentModelHost;
using NuGet.VisualStudio;
using TPL = System.Threading.Tasks;
Expand All @@ -23,9 +24,10 @@ public NugetInstaller(IPackageHandler successor)
}

/// <inheritdoc/>
public override async TPL.Task Execute(Project project)
public override async TPL.Task ExecuteAsync(Project project)
{
var componentModel = (IComponentModel)await this.Package.GetServiceAsync(typeof(SComponentModel));
Assumes.Present(componentModel);
IVsPackageInstaller packageInstaller = componentModel.GetService<IVsPackageInstaller>();
packageInstaller.InstallPackage(
null,
Expand All @@ -34,7 +36,7 @@ public override async TPL.Task Execute(Project project)
version: (string)null, // install latest stable version
ignoreDependencies: false);

await this.Successor.Execute(project);
await this.Successor.ExecuteAsync(project);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Microsoft.VisualStudio.SlowCheetah.VS
using System.Linq;
using EnvDTE;
using Microsoft.Build.Construction;
using Microsoft.VisualStudio.Shell;
using TPL = System.Threading.Tasks;

/// <summary>
Expand All @@ -23,10 +24,11 @@ public TargetsUninstaller(IPackageHandler successor)
}

/// <inheritdoc/>
public override async TPL.Task Execute(Project project)
public override async TPL.Task ExecuteAsync(Project project)
{
// We handle any NuGet package logic before editing the project file
await this.Successor.Execute(project);
await this.Successor.ExecuteAsync(project);
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

project.Save();
ProjectRootElement projectRoot = ProjectRootElement.Open(project.FullName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Microsoft.VisualStudio.SlowCheetah.VS
using System;
using System.Threading.Tasks;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;

/// <summary>
Expand All @@ -28,8 +29,9 @@ public UserInstallationHandler(IPackageHandler successor)
/// <param name="title">The title of the message box</param>
/// <param name="message">The message to be shown</param>
/// <returns>True if the user has accepted the warning message</returns>
protected async Task<bool> HasUserAcceptedWarningMessage(string title, string message)
protected async Task<bool> HasUserAcceptedWarningMessageAsync(string title, string message)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
var shell = (IVsUIShell)await this.Package.GetServiceAsync(typeof(SVsUIShell));

if (shell != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ namespace Microsoft.VisualStudio.SlowCheetah.VS
using System;
using System.Collections.Generic;
using EnvDTE;
using Microsoft;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using NuGet.VisualStudio;
using NuGet.VisualStudio.Contracts;
using TPL = System.Threading.Tasks;

/// <summary>
Expand Down Expand Up @@ -71,9 +73,10 @@ public SlowCheetahNuGetManager(AsyncPackage package)
/// <returns>True if the project supports NuGet</returns>
/// <remarks>This implementation is derived of the internal NuGet method IsSupported
/// https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/Utility/EnvDTEProjectUtility.cs#L441
/// This should be removed when NuGet adds this to their public API</remarks>
/// This should be removed when NuGet adds this to their public API.</remarks>
public bool ProjectSupportsNuget(IVsHierarchy hierarchy)
{
ThreadHelper.ThrowIfNotOnUIThread();
if (hierarchy == null)
{
throw new ArgumentNullException(nameof(hierarchy));
Expand Down Expand Up @@ -113,8 +116,9 @@ public bool ProjectSupportsNuget(IVsHierarchy hierarchy)
/// </summary>
/// <param name="hierarchy">Hierarchy of the project to be verified</param>
/// <returns>A <see cref="TPL.Task"/> representing the asynchronous operation.</returns>
public async TPL.Task CheckSlowCheetahInstallation(IVsHierarchy hierarchy)
public async TPL.Task CheckSlowCheetahInstallationAsync(IVsHierarchy hierarchy)
{
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
if (hierarchy == null)
{
throw new ArgumentNullException(nameof(hierarchy));
Expand Down Expand Up @@ -160,22 +164,24 @@ public async TPL.Task CheckSlowCheetahInstallation(IVsHierarchy hierarchy)
plan = new BackgroundInstallationHandler(plan)
{
// If the old package is installed, this is an update operation
IsUpdate = isOldScPackageInstalled
IsUpdate = isOldScPackageInstalled,
};
}

await plan.Execute(currentProject);
await plan.ExecuteAsync(currentProject);
}

private static IVsPackageInstallerServices GetInstallerServices(IServiceProvider package)
{
var componentModel = (IComponentModel)package.GetService(typeof(SComponentModel));
Assumes.Present(componentModel);
IVsPackageInstallerServices installerServices = componentModel.GetService<IVsPackageInstallerServices>();
return installerServices;
}

private static bool IsOldSlowCheetahInstalled(IVsBuildPropertyStorage buildPropertyStorage)
{
ThreadHelper.ThrowIfNotOnUIThread();
buildPropertyStorage.GetPropertyValue("SlowCheetahImport", null, (uint)_PersistStorageType.PST_PROJECT_FILE, out string propertyValue);
if (!string.IsNullOrEmpty(propertyValue))
{
Expand All @@ -193,6 +199,7 @@ private static bool IsOldSlowCheetahInstalled(IVsBuildPropertyStorage buildPrope

private static bool SupportsINugetProjectSystem(IVsHierarchy hierarchy)
{
ThreadHelper.ThrowIfNotOnUIThread();
var vsProject = hierarchy as IVsProject;
if (vsProject == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ protected override IWin32Window Window
/// <inheritdoc/>
public override void SaveSettingsToXml(IVsSettingsWriter writer)
{
Shell.ThreadHelper.ThrowIfNotOnUIThread();
try
{
base.SaveSettingsToXml(writer);
Expand All @@ -68,6 +69,7 @@ public override void SaveSettingsToXml(IVsSettingsWriter writer)
/// <inheritdoc/>
public override void LoadSettingsFromXml(IVsSettingsReader reader)
{
Shell.ThreadHelper.ThrowIfNotOnUIThread();
try
{
this.InitializeDefaults();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected override IWin32Window Window
/// <inheritdoc/>
public override void SaveSettingsToXml(IVsSettingsWriter writer)
{
Shell.ThreadHelper.ThrowIfNotOnUIThread();
try
{
base.SaveSettingsToXml(writer);
Expand All @@ -70,6 +71,7 @@ public override void SaveSettingsToXml(IVsSettingsWriter writer)
/// <inheritdoc/>
public override void LoadSettingsFromXml(IVsSettingsReader reader)
{
Shell.ThreadHelper.ThrowIfNotOnUIThread();
try
{
this.InitializeDefaults();
Expand Down
Loading