Skip to content

Commit b9ddf9e

Browse files
Stop binding assembly versions at all, and add version info
1 parent 1308d42 commit b9ddf9e

File tree

5 files changed

+35
-68
lines changed

5 files changed

+35
-68
lines changed

Vsix/CodeConversion.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ internal class CodeConversion
2525
private readonly IAsyncServiceProvider _serviceProvider;
2626
private readonly JoinableTaskFactory _joinableTaskFactory;
2727
private readonly VisualStudioWorkspace _visualStudioWorkspace;
28-
public static readonly string ConverterTitle = "Code converter";
2928
private static readonly string Intro = Environment.NewLine + Environment.NewLine + new string(Enumerable.Repeat('-', 80).ToArray()) + Environment.NewLine;
3029
private readonly OutputWindow _outputWindow;
3130
private readonly Cancellation _packageCancellation;

Vsix/CodeConverterPackage.cs

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -84,58 +84,17 @@ public sealed class CodeConverterPackage : AsyncPackage
8484

8585
internal Cancellation PackageCancellation { get; } = new Cancellation();
8686

87-
private readonly AssemblyName _thisAssemblyName;
88-
private readonly HashSet<string> _ourAssemblyNames;
8987
/// <summary>
9088
/// Initializes a new instance of package class.
9189
/// </summary>
9290
public CodeConverterPackage()
9391
{
94-
var thisAssembly = GetType().Assembly;
95-
_thisAssemblyName = thisAssembly.GetName();
96-
_ourAssemblyNames = new HashSet<string>(new[] { _thisAssemblyName }.Concat(thisAssembly.GetReferencedAssemblies().Where(a => a.Name.StartsWith("ICSharpCode"))).Select(a => a.FullName));
9792
// Inside this method you can place any initialization code that does not require
9893
// any Visual Studio service because at this point the package object is created but
9994
// not sited yet inside Visual Studio environment. The place to do all the other
10095
// initialization is the Initialize method.
10196
}
10297

103-
// System.Threading.Tasks.Dataflow 4.5.24.0 shipped with VS2017 15.9.21+28307.1064 but we want to target 4.6.0.0
104-
private Assembly LoadWithoutVersionForOurDependencies(object sender, ResolveEventArgs args)
105-
{
106-
var requestedAssemblyName = new AssemblyName(args.Name);
107-
if (requestedAssemblyName.Version != null && IsThisExtensionRequestingAssembly()) {
108-
return LoadAnyVersionOfAssembly(requestedAssemblyName);
109-
}
110-
return null;
111-
112-
}
113-
114-
private static Assembly LoadAnyVersionOfAssembly(AssemblyName assemblyName)
115-
{
116-
try {
117-
return Assembly.Load(new AssemblyName(assemblyName.Name){CultureName = assemblyName.CultureName});
118-
} catch (FileNotFoundException e) when (e.FileName.Contains("Microsoft.VisualStudio.LanguageServices") && ProbablyRequiresVsUpgrade) {
119-
MessageBox.Show(
120-
"Code Converter cannot find `Microsoft.VisualStudio.LanguageServices`. Please upgrade Visual Studio to version 15.9.3 or above.\r\n\r\n" +
121-
"If after upgrading you still see this error, attach your activity log %AppData%\\Microsoft\\VisualStudio\\<version>\\ActivityLog.xml to a GitHub issue at https://github.com/icsharpcode/CodeConverter \r\n\r\n" +
122-
"You can press Ctrl + C to copy this message",
123-
"Upgrade Visual Studio", MessageBoxButton.OK);
124-
return null;
125-
}
126-
}
127-
128-
private bool IsThisExtensionRequestingAssembly()
129-
{
130-
return GetPossibleRequestingAssemblies().Any(requesting => _ourAssemblyNames.Contains(requesting.FullName));
131-
}
132-
133-
private IEnumerable<AssemblyName> GetPossibleRequestingAssemblies()
134-
{
135-
return new StackTrace().GetFrames().Select(f => f.GetMethod().DeclaringType?.Assembly)
136-
.Select(a => a.GetName()).SkipWhile(a => Equals(a, _thisAssemblyName));
137-
}
138-
13998
/// <summary>
14099
/// Initialization of the package; this method is called right after the package is sited, so this is the place
141100
/// where you can put all the initialization code that rely on services provided by VisualStudio.
@@ -155,25 +114,6 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
155114
await base.InitializeAsync(cancellationToken, progress);
156115
}
157116

158-
public static bool ProbablyRequiresVsUpgrade {
159-
get {
160-
var version = FullVsVersion;
161-
return version == null || version < new Version(15, 9, 3, 0);
162-
}
163-
}
164-
165-
private static Version FullVsVersion {
166-
get {
167-
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "msenv.dll");
168-
169-
if (File.Exists(path)) {
170-
var fvi = FileVersionInfo.GetVersionInfo(path);
171-
return new Version(fvi.ProductMajorPart, fvi.ProductMinorPart, fvi.ProductBuildPart,
172-
fvi.ProductPrivatePart);
173-
} else return null;
174-
}
175-
}
176-
177117
internal OleMenuCommandWithBlockingStatus CreateCommand(Func<CancellationToken, Task> callbackAsync, CommandID menuCommandId)
178118
{
179119
return new OleMenuCommandWithBlockingStatus(JoinableTaskFactory, PackageCancellation, callbackAsync, menuCommandId);

Vsix/ConvertCSToVBCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private async Task SolutionOrProjectMenuItemCallbackAsync(CancellationToken canc
167167
var projects = VisualStudioInteraction.GetSelectedProjectsAsync(ProjectExtension);
168168
await _codeConversion.ConvertProjectsAsync<CSToVBConversion>(await projects, cancellationToken);
169169
} catch (Exception ex) {
170-
await VisualStudioInteraction.ShowExceptionAsync(ServiceProvider, CodeConversion.ConverterTitle, ex);
170+
await VisualStudioInteraction.ShowExceptionAsync(ex);
171171
}
172172
}
173173

@@ -179,7 +179,7 @@ private async Task ConvertDocumentAsync(string documentPath, Span selected, Canc
179179
try {
180180
await _codeConversion.ConvertDocumentAsync<CSToVBConversion>(documentPath, selected, cancellationToken);
181181
} catch (Exception ex) {
182-
await VisualStudioInteraction.ShowExceptionAsync(ServiceProvider, CodeConversion.ConverterTitle, ex);
182+
await VisualStudioInteraction.ShowExceptionAsync(ex);
183183
}
184184
}
185185
}

Vsix/ConvertVBToCSCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ private async Task SolutionOrProjectMenuItemCallbackAsync(CancellationToken canc
167167
var projects = VisualStudioInteraction.GetSelectedProjectsAsync(ProjectExtension);
168168
await _codeConversion.ConvertProjectsAsync<VBToCSConversion>(await projects, cancellationToken);
169169
} catch (Exception ex) {
170-
await VisualStudioInteraction.ShowExceptionAsync(ServiceProvider, CodeConversion.ConverterTitle, ex);
170+
await VisualStudioInteraction.ShowExceptionAsync(ex);
171171
}
172172
}
173173

@@ -179,7 +179,7 @@ private async Task ConvertDocumentAsync(string documentPath, Span selected, Canc
179179
try {
180180
await _codeConversion.ConvertDocumentAsync<VBToCSConversion>(documentPath, selected, cancellationToken);
181181
} catch (Exception ex) {
182-
await VisualStudioInteraction.ShowExceptionAsync(ServiceProvider, CodeConversion.ConverterTitle, ex);
182+
await VisualStudioInteraction.ShowExceptionAsync(ex);
183183
}
184184
}
185185
}

Vsix/VisualStudioInteraction.cs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.IO;
45
using System.Linq;
6+
using System.Reflection;
57
using System.Runtime.InteropServices;
68
using System.Threading;
79
using System.Threading.Tasks;
810
using System.Windows;
911
using EnvDTE;
1012
using EnvDTE80;
13+
using ICSharpCode.CodeConverter.Shared;
1114
using Microsoft.VisualStudio;
1215
using Microsoft.VisualStudio.Editor;
1316
using Microsoft.VisualStudio.Shell;
@@ -35,6 +38,24 @@ internal static class VisualStudioInteraction
3538
internal static DTE2 Dte => m_Dte ?? (m_Dte = Package.GetGlobalService(typeof(DTE)) as DTE2);
3639

3740
private static CancellationToken CancelAllToken;
41+
private static readonly Version m_LowestSupportedVersion = new Version(15, 7, 0, 0);
42+
private static readonly Version m_FullVsVersion = GetFullVsVersion();
43+
private static readonly string m_Title = "Code converter " + new AssemblyName(typeof(CodeConversion).Assembly.FullName).Version.ToString(3) + " - Visual Studio " + m_FullVsVersion;
44+
45+
private static Version GetFullVsVersion()
46+
{
47+
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "msenv.dll");
48+
49+
if (File.Exists(path)) {
50+
var fvi = FileVersionInfo.GetVersionInfo(path);
51+
return new Version(fvi.ProductMajorPart, fvi.ProductMinorPart, fvi.ProductBuildPart,
52+
fvi.ProductPrivatePart);
53+
} else {
54+
return null;
55+
}
56+
}
57+
58+
3859
internal static void Initialize(Cancellation packageCancellation)
3960
{
4061
CancelAllToken = packageCancellation.CancelAll;
@@ -86,12 +107,19 @@ public static async Task<ITextDocument> GetTextDocumentAsync(this IWpfTextViewHo
86107
return textDocument;
87108
}
88109

89-
public static async Task ShowExceptionAsync(IAsyncServiceProvider serviceProvider, string title, Exception ex)
110+
public static async Task ShowExceptionAsync(Exception ex)
90111
{
91112
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(CancelAllToken);
92113
if (!CancelAllToken.IsCancellationRequested) {
93-
MessageBox.Show($"An error has occured during conversion - press Ctrl+C to copy the details: {ex}",
94-
title, MessageBoxButton.OK, MessageBoxImage.Error);
114+
var versionMessageSuffix = "";
115+
if (m_FullVsVersion < m_LowestSupportedVersion) {
116+
versionMessageSuffix = $"{Environment.NewLine}This extension only supports VS {m_LowestSupportedVersion}+, you are currently using {m_FullVsVersion}";
117+
}
118+
if (m_FullVsVersion.Major < 16) {
119+
versionMessageSuffix = $"{Environment.NewLine}Support for VS2017 (15.*) is likely to end this year. You're using: {m_FullVsVersion}";
120+
}
121+
MessageBox.Show($"An error has occured during conversion - press Ctrl+C to copy the details: {ex}{versionMessageSuffix}",
122+
m_Title, MessageBoxButton.OK, MessageBoxImage.Error);
95123
}
96124
}
97125

0 commit comments

Comments
 (0)