Skip to content

Commit

Permalink
Merge pull request #113 from StefanKert/vs2022support
Browse files Browse the repository at this point in the history
Add VS 2022 support
  • Loading branch information
StefanKert authored Feb 21, 2022
2 parents 05b50d1 + 734accb commit e57cb7a
Show file tree
Hide file tree
Showing 28 changed files with 218 additions and 213 deletions.
6 changes: 0 additions & 6 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
<Version>3.1.91</Version>
<PrivateAssets>all</PrivateAssets>
</PackageReference>

<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

</ItemGroup>

<PropertyGroup>
Expand Down
5 changes: 4 additions & 1 deletion src/BuildVision.Contracts/BuildVision.Contracts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
</ItemGroup>

<ItemGroup>
<Reference Include="Microsoft.Build.Framework" />
<PackageReference Include="Microsoft.Build.Framework" Version="16.0.461"/>
</ItemGroup>

<ItemGroup>
<Reference Include="PresentationFramework" />
</ItemGroup>

Expand Down
11 changes: 8 additions & 3 deletions src/BuildVision.UI/BuildVision.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,19 @@
<PackageReference Include="AppInsights.WindowsDesktop">
<Version>2.10.55</Version>
</PackageReference>
<PackageReference Include="Madskristensen.VisualStudio.SDK">
<Version>14.3.81-pre</Version>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers">
<Version>3.0.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers">
<Version>6.0.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.SDK">
<Version>16.0.206</Version>
</PackageReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
2 changes: 1 addition & 1 deletion src/BuildVision.UI/Resources/BuildState.Resources.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.14.0">
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0">


<Style x:Key="MainIcon" TargetType="{x:Type ContentControl}">
Expand Down
2 changes: 1 addition & 1 deletion src/BuildVision.UI/Resources/CommonResources.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.14.0">
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0">

<!-- Toolbar button style -->
<Style x:Key="ToolBarButtonBaseStyle" TargetType="{x:Type ButtonBase}">
Expand Down
2 changes: 1 addition & 1 deletion src/BuildVision.UI/Resources/ValueIndicator.Resources.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.14.0">
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0">

<ControlTemplate x:Key="ErrorsIndicatorIcon">
<Viewbox Stretch="Uniform">
Expand Down
2 changes: 1 addition & 1 deletion src/BuildVision.UI/Styles/ExtensionStyle.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:environment="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.14.0">
xmlns:environment="clr-namespace:Microsoft.VisualStudio.PlatformUI;assembly=Microsoft.VisualStudio.Shell.15.0">

<SolidColorBrush x:Key="ToolWindowBackgroundKey" Color="{DynamicResource {x:Static environment:EnvironmentColors.ToolWindowBackgroundColorKey}}"/>
<SolidColorBrush x:Key="ToolboxBackgroundKey" Color="{DynamicResource {x:Static environment:EnvironmentColors.ToolboxBackgroundColorKey}}"/>
Expand Down
2 changes: 1 addition & 1 deletion src/BuildVision.UI/Styles/ScrollViewerStyle.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.14.0"
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0"
xmlns:converters="clr-namespace:BuildVision.UI.Converters">

<converters:ParameterIsEqualsValueConverter x:Key="ParameterIsEqualsValueConverter" />
Expand Down
2 changes: 1 addition & 1 deletion src/BuildVision.UI/Themes/Generic.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:ui="clr-namespace:BuildVision.UI.Controls.Buttons"
xmlns:indicators="clr-namespace:BuildVision.UI.Controls.Indicators"
xmlns:res="clr-namespace:BuildVision.UI"
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.14.0">
xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.15.0">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/BuildVision.UI;component/Resources/CommonResources.xaml" />
<ResourceDictionary Source="/BuildVision.UI;component/Resources/BuildAction.Resources.xaml" />
Expand Down
18 changes: 12 additions & 6 deletions src/BuildVision/BuildVision.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<Compile Include="Extensions\IServiceProviderExtensions.cs" />
<Compile Include="Properties\GlobalSuppressions.cs" />
<Compile Include="Services\BuildInformationProvider.cs" />
<Compile Include="Services\BuildLoggerProvider.cs" />
<Compile Include="Services\ErrorNavigationService.cs" />
<Compile Include="Interfaces\IWindowStateService.cs" />
<Compile Include="Services\SolutionProvider.cs" />
Expand Down Expand Up @@ -221,8 +222,8 @@
<PackageReference Include="AppInsights.WindowsDesktop">
<Version>2.10.55</Version>
</PackageReference>
<PackageReference Include="Madskristensen.VisualStudio.SDK">
<Version>14.3.81-pre</Version>
<PackageReference Include="Community.VisualStudio.Toolkit.15">
<Version>15.0.339</Version>
</PackageReference>
<PackageReference Include="Microsoft.Build">
<Version>16.0.461</Version>
Expand All @@ -241,12 +242,17 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.SDK.Analyzers">
<Version>16.6.11</Version>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers">
<Version>6.0.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.SDK">
<Version>16.0.206</Version>
</PackageReference>
<PackageReference Include="Microsoft.VSSDK.BuildTools">
<Version>16.7.3069</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<Version>17.0.5232</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Serilog">
Expand Down
73 changes: 10 additions & 63 deletions src/BuildVision/Core/BuildVisionPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using BuildVision.Common.Diagnostics;
using BuildVision.Common.Logging;
using BuildVision.Exports.Providers;
using BuildVision.Helpers;
using BuildVision.Tool;
using BuildVision.UI;
using BuildVision.UI.Settings.Models;
Expand Down Expand Up @@ -43,21 +42,15 @@ namespace BuildVision.Core
[ProvideOptionPage(typeof(ProjectItemSettingsDialogPage), "BuildVision", "Project Item", 0, 0, true)]
public sealed class BuildVisionPackage : AsyncPackage
{
private DTE _dte;
private DTE2 _dte2;
private CommandEvents _commandEvents;
private SolutionEvents _solutionEvents;
private WindowEvents _windowEvents;
private DTE2 _dte;
private IVsSolutionBuildManager2 _solutionBuildManager;
private IVsSolutionBuildManager5 _solutionBuildManager4;
private IBuildInformationProvider _buildInformationProvider;
private uint _updateSolutionEventsCookie;
private uint _updateSolutionEvents4Cookie;
private SolutionBuildEvents _solutionBuildEvents;
private ISolutionProvider _solutionProvider;
private ServiceProvider _serviceProvider;
private ILogger _logger = LogManager.ForContext<BuildVisionPackage>();
private Window _activeProjectContext;

public static BuildVisionPackage BuildVisionPackageInstance { get; set; }

Expand All @@ -80,16 +73,16 @@ public BuildVisionPackage()
BuildVisionPackageInstance = this;
}

public static Version VisualStudioVersion => GetGlobalService(typeof(DTE)) is DTE dte
public static Version VisualStudioVersion => GetGlobalService(typeof(DTE2)) is DTE2 dte
? new Version(int.Parse(dte.Version.Split('.')[0], CultureInfo.InvariantCulture), 0)
: new Version(0, 0, 0, 0);

private string GetEdition()
{
try
{
_dte2 = GetService(typeof(DTE)) as DTE2;
return _dte2.Edition;
_dte = GetService(typeof(DTE)) as DTE2;
return _dte.Edition;
}
catch (Exception ex)
{
Expand All @@ -111,10 +104,8 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
await JoinableTaskFactory.SwitchToMainThreadAsync(DisposalToken);
await ShowToolWindowCommand.InitializeAsync(this);

_dte = await GetServiceAsync(typeof(DTE)) as DTE;
_dte = await GetServiceAsync(typeof(DTE)) as DTE2;
Assumes.Present(_dte);
_dte2 = await GetServiceAsync(typeof(DTE)) as DTE2;
Assumes.Present(_dte2);
_solutionBuildManager = await GetServiceAsync(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
Assumes.Present(_solutionBuildManager);
_solutionBuildManager4 = await GetServiceAsync(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager5;
Expand All @@ -123,57 +114,24 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
Assumes.Present(_buildInformationProvider);
_solutionProvider = await GetServiceAsync(typeof(ISolutionProvider)) as ISolutionProvider;
Assumes.Present(_solutionProvider);
_serviceProvider = new ServiceProvider(Services.Dte as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
Assumes.Present(_serviceProvider);

_commandEvents = _dte.Events.CommandEvents;
_commandEvents.AfterExecute += CommandEvents_AfterExecute;
Community.VisualStudio.Toolkit.VS.Events.SolutionEvents.OnBeforeOpenSolution += SolutionEvents_Opened;
Community.VisualStudio.Toolkit.VS.Events.SolutionEvents.OnBeforeCloseSolution += SolutionEvents_AfterClosing;

_solutionEvents = _dte.Events.SolutionEvents;
_solutionEvents.AfterClosing += SolutionEvents_AfterClosing;
_solutionEvents.Opened += SolutionEvents_Opened;

_windowEvents = _dte.Events.WindowEvents;
_windowEvents.WindowActivated += WindowEvents_WindowActivated;

if (_dte2.Solution?.IsOpen == true)
if (_dte.Solution?.IsOpen == true)
{
SolutionEvents_Opened();
}
}

private void WindowEvents_WindowActivated(Window gotFocus, Window lostFocus)
{
if (gotFocus == null)
return;

switch (gotFocus.Type)
{
case vsWindowType.vsWindowTypeSolutionExplorer:
_activeProjectContext = gotFocus;
break;

case vsWindowType.vsWindowTypeDocument:
case vsWindowType.vsWindowTypeDesigner:
case vsWindowType.vsWindowTypeCodeWindow:
if (gotFocus.Project != null && !gotFocus.Project.IsHidden())
_activeProjectContext = gotFocus;
break;

default:
return;
}
}

private void SolutionEvents_Opened()
private void SolutionEvents_Opened(string solutionFileName = "")
{
ThreadHelper.ThrowIfNotOnUIThread();

_solutionProvider.ReloadSolution();
_buildInformationProvider.ResetCurrentProjects();
_buildInformationProvider.ResetBuildInformationModel();

_solutionBuildEvents = new SolutionBuildEvents(_solutionProvider, _buildInformationProvider, _serviceProvider, LogManager.ForContext<SolutionBuildEvents>());
_solutionBuildEvents = new SolutionBuildEvents(_solutionProvider, _buildInformationProvider, LogManager.ForContext<SolutionBuildEvents>());
_solutionBuildManager.AdviseUpdateSolutionEvents(_solutionBuildEvents, out _updateSolutionEventsCookie);
_solutionBuildManager4.AdviseUpdateSolutionEvents4(_solutionBuildEvents, out _updateSolutionEvents4Cookie);
}
Expand All @@ -191,16 +149,5 @@ private void SolutionEvents_AfterClosing()

DiagnosticsClient.Flush();
}

private void CommandEvents_AfterExecute(string guid, int id, object customIn, object customOut)
{
if (id == (int)VSConstants.VSStd97CmdID.CancelBuild
&& Guid.Parse(guid) == VSConstants.GUID_VSStandardCommandSet97)
{
//_buildCancelled = true;
//if (!_buildCancelledInternally)
// OnBuildCancelled();
}
}
}
}
7 changes: 7 additions & 0 deletions src/BuildVision/Core/ServiceProviderPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using BuildVision.Views.Settings;
using Microsoft;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.BuildLogging;
using Task = System.Threading.Tasks.Task;

namespace BuildVision.Core
Expand All @@ -24,6 +25,7 @@ namespace BuildVision.Core
[ProvideService(typeof(ISolutionProvider), IsAsyncQueryable = true)]
[ProvideService(typeof(IBuildMessagesFactory), IsAsyncQueryable = true)]
[ProvideService(typeof(IBuildOutputLogger), IsAsyncQueryable = true)]
[ProvideService(typeof(IVsBuildLoggerProvider), IsAsyncQueryable = true)]
[ProvideService(typeof(IBuildService), IsAsyncQueryable = true)]
[ProvideService(typeof(IStatusBarNotificationService), IsAsyncQueryable = true)]
[ProvideService(typeof(IWindowStateService), IsAsyncQueryable = true)]
Expand All @@ -46,6 +48,7 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
AddService(typeof(IWindowStateService), CreateServiceAsync, true);
AddService(typeof(ITaskBarInfoService), CreateServiceAsync, true);
AddService(typeof(IErrorNavigationService), CreateServiceAsync, true);
AddService(typeof(IVsBuildLoggerProvider), CreateServiceAsync, true);
}

async Task<object> CreateServiceAsync(IAsyncServiceContainer container, CancellationToken cancellation, Type serviceType)
Expand All @@ -69,6 +72,10 @@ async Task<object> CreateServiceAsync(IAsyncServiceContainer container, Cancella
{
return new BuildOutputLogger(_parsingErrorsLoggerId, Microsoft.Build.Framework.LoggerVerbosity.Quiet);
}
else if (serviceType == typeof(IVsBuildLoggerProvider))
{
return new BuildLoggerProvider();
}
else if (serviceType == typeof(IErrorNavigationService))
{
return new ErrorNavigationService(sp);
Expand Down
2 changes: 1 addition & 1 deletion src/BuildVision/Core/Services.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static Ret GetGlobalService<T, Ret>(IServiceProvider provider = null) where T :
public static IComponentModel ComponentModel => GetGlobalService<SComponentModel, IComponentModel>();
public static ExportProvider DefaultExportProvider => ComponentModel.DefaultExportProvider;

public static DTE Dte => GetGlobalService<DTE, DTE>();
public static DTE2 Dte => GetGlobalService<DTE, DTE2>();

public static DTE2 Dte2 => Dte as DTE2;

Expand Down
23 changes: 4 additions & 19 deletions src/BuildVision/Core/SolutionBuildEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using BuildVision.Contracts;
using BuildVision.Exports.Providers;
using BuildVision.Helpers;
using BuildVision.Tool.Building;
using BuildVision.Tool.Models;
using EnvDTE;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;
using Serilog;
Expand All @@ -15,28 +15,26 @@ public class SolutionBuildEvents : IVsUpdateSolutionEvents2, IVsUpdateSolutionEv
private readonly ISolutionProvider _solutionProvider;
private readonly IBuildInformationProvider _buildInformationProvider;
private readonly ILogger _logger;
private readonly BuildEvents _buildEvents;
private BuildAction _currentBuildAction;

public SolutionBuildEvents(
ISolutionProvider solutionProvider,
IBuildInformationProvider buildInformationProvider,
IServiceProvider serviceProvider,
ILogger logger)
{
_solutionProvider = solutionProvider;
_buildInformationProvider = buildInformationProvider;
_logger = logger;
_buildEvents = (serviceProvider.GetService(typeof(DTE)) as DTE).Events.BuildEvents;
_buildEvents.OnBuildBegin += BuildEvents_OnBuildBegin;
}

public void UpdateSolution_BeginUpdateAction(uint dwAction)
{
try
{
_solutionProvider.ReloadSolution();
BuildLoggerProvider.BuildOutputLogger?.Clear();
_currentBuildAction = StateConverterHelper.ConvertSolutionBuildFlagsToBuildAction(dwAction, (VSSOLNBUILDUPDATEFLAGS)dwAction);
_buildInformationProvider.BuildStarted(_currentBuildAction, BuildScope.Solution);
_buildInformationProvider.ReloadCurrentProjects();
}
catch (Exception ex)
Expand All @@ -46,19 +44,7 @@ public void UpdateSolution_BeginUpdateAction(uint dwAction)
}
}

private void BuildEvents_OnBuildBegin(vsBuildScope scope, vsBuildAction action)
{
try
{
// We use the action from UpdateSolution_BeginUpdateAction here because it givs closer details on the current action
_buildInformationProvider.BuildStarted(_currentBuildAction, (BuildScope)scope);
}
catch (Exception ex)
{
_logger.Error(ex, "");
throw;
}
}
public int UpdateSolution_Begin(ref int pfCancelUpdate) => VSConstants.S_OK;

public int UpdateProjectCfg_Begin(IVsHierarchy pHierProj, IVsCfg pCfgProj, IVsCfg pCfgSln, uint dwAction, ref int pfCancel)
{
Expand Down Expand Up @@ -108,7 +94,6 @@ public int UpdateSolution_Done(int fSucceeded, int fModified, int fCancelCommand
}

#region Interface Implementation
public int UpdateSolution_Begin(ref int pfCancelUpdate) => VSConstants.S_OK;
public int UpdateSolution_StartUpdate(ref int pfCancelUpdate) => VSConstants.S_OK;
public int UpdateSolution_Cancel() => VSConstants.S_OK;
public int OnActiveProjectCfgChange(IVsHierarchy pIVsHierarchy) => VSConstants.S_OK;
Expand Down
Loading

0 comments on commit e57cb7a

Please sign in to comment.