Skip to content
Draft
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
6 changes: 6 additions & 0 deletions Vsix/CodeConverterPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.ComponentModelHost;
using Microsoft.VisualStudio.Extensibility;
using Microsoft.VisualStudio.LanguageServices;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Threading;
Expand Down Expand Up @@ -85,6 +86,9 @@ public sealed class CodeConverterPackage : AsyncPackage
public const string ConvertableSolutionMenuVisibilityGuid = "8e7192d0-28b7-4fe7-8d84-82c1db98d459";

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

internal static CodeConversion CodeConversionInstance { get; private set; }
internal static CodeConverterPackage Instance { get; private set; }

/// <summary>
/// Initializes a new instance of package class.
Expand All @@ -109,6 +113,8 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
var visualStudioWorkspace = componentModel.GetService<VisualStudioWorkspace>();
var codeConversion = await CodeConversion.CreateAsync(this, visualStudioWorkspace, this.GetDialogPageAsync<ConverterOptionsPage>);
CodeConversionInstance = codeConversion;
Instance = this;
ConvertCSToVBCommand.Initialize(this, oleMenuCommandService, codeConversion);
ConvertVBToCSCommand.Initialize(this, oleMenuCommandService, codeConversion);
PasteAsVB.Initialize(this, oleMenuCommandService, codeConversion);
Expand Down
45 changes: 45 additions & 0 deletions Vsix/ConvertCSToVBExtensibilityCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Extensibility;
using Microsoft.VisualStudio.Extensibility.Commands;

namespace ICSharpCode.CodeConverter.VsExtension;

[VisualStudioContribution]
public class ConvertCSToVBExtensibilityCommand : Command
{
private readonly CodeConverterPackage _package;

public ConvertCSToVBExtensibilityCommand(CodeConverterPackage package)
{
_package = package;
}

public override CommandConfiguration CommandConfiguration => new("%a3378a21-e939-40c9-9e4b-eb0cec7b7854%");

public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken)
{
var codeConversion = CodeConverterPackage.CodeConversionInstance;
var serviceProvider = CodeConverterPackage.Instance;
if (codeConversion == null || serviceProvider == null) return;

var itemsPath = await VisualStudioInteraction.GetSelectedItemsPathAsync(CodeConversion.IsCSFileName);
if (itemsPath.Count > 0)
{
await codeConversion.ConvertDocumentsAsync<ICSharpCode.CodeConverter.VB.CSToVBConversion>(itemsPath, cancellationToken);
return;
}

var projects = await VisualStudioInteraction.GetSelectedProjectsAsync(".csproj");
if (projects.Count > 0)
{
await codeConversion.ConvertProjectsAsync<ICSharpCode.CodeConverter.VB.CSToVBConversion>(projects, cancellationToken);
return;
}

(string filePath, var selection) = await VisualStudioInteraction.GetCurrentFilenameAndSelectionAsync(serviceProvider, CodeConversion.IsCSFileName, false);
if (filePath != null && selection != null) {
await codeConversion.ConvertDocumentAsync<ICSharpCode.CodeConverter.VB.CSToVBConversion>(filePath, selection.Value, cancellationToken);
}
}
}
45 changes: 45 additions & 0 deletions Vsix/ConvertVBToCSExtensibilityCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Extensibility;
using Microsoft.VisualStudio.Extensibility.Commands;

namespace ICSharpCode.CodeConverter.VsExtension;

[VisualStudioContribution]
public class ConvertVBToCSExtensibilityCommand : Command
{
private readonly CodeConverterPackage _package;

public ConvertVBToCSExtensibilityCommand(CodeConverterPackage package)
{
_package = package;
}

public override CommandConfiguration CommandConfiguration => new("%a3378a21-e939-40c9-9e4b-eb0cec7b7854%");

public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken)
{
var codeConversion = CodeConverterPackage.CodeConversionInstance;
var serviceProvider = CodeConverterPackage.Instance;
if (codeConversion == null || serviceProvider == null) return;

var itemsPath = await VisualStudioInteraction.GetSelectedItemsPathAsync(CodeConversion.IsVBFileName);
if (itemsPath.Count > 0)
{
await codeConversion.ConvertDocumentsAsync<ICSharpCode.CodeConverter.CSharp.VBToCSConversion>(itemsPath, cancellationToken);
return;
}

var projects = await VisualStudioInteraction.GetSelectedProjectsAsync(".vbproj");
if (projects.Count > 0)
{
await codeConversion.ConvertProjectsAsync<ICSharpCode.CodeConverter.CSharp.VBToCSConversion>(projects, cancellationToken);
return;
}

(string filePath, var selection) = await VisualStudioInteraction.GetCurrentFilenameAndSelectionAsync(serviceProvider, CodeConversion.IsVBFileName, false);
if (filePath != null && selection != null) {
await codeConversion.ConvertDocumentAsync<ICSharpCode.CodeConverter.CSharp.VBToCSConversion>(filePath, selection.Value, cancellationToken);
}
}
}
12 changes: 12 additions & 0 deletions Vsix/Extension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Microsoft.VisualStudio.Extensibility;

namespace ICSharpCode.CodeConverter.VsExtension;

[VisualStudioContribution]
public class CodeConverterExtension : Extension
{
public override ExtensionConfiguration ExtensionConfiguration => new() {
RequiresInProcessHosting = true,
Metadata = null
};
}
9 changes: 7 additions & 2 deletions Vsix/VisualStudioInteraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ internal static class VisualStudioInteraction
{
private static DTE2 _dte;

/// <remarks>All calls and usages must be from the main thread</remarks>>
internal static DTE2 Dte => _dte ??= Package.GetGlobalService(typeof(DTE)) as DTE2;
/// <remarks>All calls and usages must be from the main thread</remarks>
internal static DTE2 Dte {
get {
ThreadHelper.ThrowIfNotOnUIThread();
return _dte ??= Package.GetGlobalService(typeof(DTE)) as DTE2;
}
}

private static CancellationToken _cancelAllToken;
private static readonly Version LowestSupportedVersion = new(16, 10, 0, 0);
Expand Down
136 changes: 22 additions & 114 deletions Vsix/Vsix.csproj
Original file line number Diff line number Diff line change
@@ -1,145 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<MinimumVisualStudioVersion>16.0</MinimumVisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SchemaVersion>2.0</SchemaVersion>
<RootNamespace>ICSharpCode.CodeConverter.VsExtension</RootNamespace>
<AssemblyName>ICSharpCode.CodeConverter.VsExtension</AssemblyName>
<ProjectGuid>{99498EF8-C9E0-433B-8D7B-EA8E9E66F0C7}</ProjectGuid>
<ProjectTypeGuids>{82B43B9B-A64C-4715-B499-D71E9CA2BD60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<TargetFramework>net472</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
<LangVersion>12</LangVersion>
<UseWPF>true</UseWPF>

<VssdkCompatibleExtension>true</VssdkCompatibleExtension>
<GeneratePkgDefFile>true</GeneratePkgDefFile>
<UseCodebase>true</UseCodebase>
<IncludeAssemblyInVSIXContainer>true</IncludeAssemblyInVSIXContainer>
<CopyBuildOutputToOutputDirectory>true</CopyBuildOutputToOutputDirectory>
<CopyOutputSymbolsToOutputDirectory>true</CopyOutputSymbolsToOutputDirectory>
<VSSDKTargetPlatformRegRootSuffix>Roslyn</VSSDKTargetPlatformRegRootSuffix>
<StartAction>Program</StartAction>
<StartProgram>$(DevEnvDir)devenv.exe</StartProgram>
<StartArguments>/rootsuffix $(VSSDKTargetPlatformRegRootSuffix)</StartArguments>
<SignAssembly>false</SignAssembly>
<DeployExtension Condition="'$(BuildingInsideVisualStudio)' != 'true'">False</DeployExtension>
<RuntimeIdentifiers>win</RuntimeIdentifiers>
<LangVersion>12.0</LangVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<IncludeDebugSymbolsInVSIXContainer>true</IncludeDebugSymbolsInVSIXContainer>
<IncludeDebugSymbolsInLocalVSIXDeployment>true</IncludeDebugSymbolsInLocalVSIXDeployment>
<CopyBuildOutputToOutputDirectory>true</CopyBuildOutputToOutputDirectory>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CopyVsixExtensionLocation>$(LocalAppData)\Microsoft\VisualStudio\15.0_8bd9890a\Extensions\frc3cnfo.23z</CopyVsixExtensionLocation>
<CopyVsixExtensionFiles Condition="Exists($(CopyVsixExtensionLocation))">True</CopyVsixExtensionFiles>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Basic.Reference.Assemblies.NetStandard20">
<Version>1.8.4</Version>
</PackageReference>
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces">
<Version>10.0.2</Version>
</PackageReference>
<!-- Build against VS 16.10 -->
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Sdk" Version="17.14.40608" PrivateAssets="all" />
<PackageReference Include="Microsoft.VisualStudio.Extensibility.Build" Version="17.14.40608" PrivateAssets="all" />
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.14.40265" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.VisualStudio.LanguageServices" Version="4.14.0" />
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="16.10.31321.278" ExcludeAssets="runtime">
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<!-- Avoids needing the VSSDK MSI installed. Version is the VS version used during compilation, not where the VSIX will be installed -->
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.5.4065">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Basic.Reference.Assemblies.NetStandard20" Version="1.8.4" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CodeConverter\CodeConverter.csproj" />
</ItemGroup>

<ItemGroup>
<VSCTCompile Include="REConverterPackage.vsct">
<ResourceName>Menus.ctmenu</ResourceName>
<SubType>Designer</SubType>
</VSCTCompile>
<Content Include="Images\refactoringessentials-logo90.png">
<IncludeInVSIX>true</IncludeInVSIX>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="Images\refactoringessentials-preview.png">
<IncludeInVSIX>true</IncludeInVSIX>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="license.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<None Include="source.extension.vsixmanifest" />
</ItemGroup>
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<ItemGroup>
<Compile Include="AppDomainExtensions.cs" />
<Compile Include="OleMenuCommandWithBlockingStatus.cs" />
<Compile Include="CodeConversion.cs" />
<Compile Include="ConvertCSToVBCommand.cs" />
<Compile Include="ConverterOptionsPage.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="ConvertVBToCSCommand.cs" />
<Compile Include="OutputWindow.cs" />
<Compile Include="Cancellation.cs" />
<Compile Include="CodeConverterPackage.cs" />
<Compile Include="PasteAsCS.cs" />
<Compile Include="PasteAsVB.cs" />
<Compile Include="ServiceProviderExtensions.cs" />
<Compile Include="SolutionProjectExtensions.cs" />
<Compile Include="TaskExtensions.cs" />
<Compile Include="VisualStudioInteraction.cs" />
<Compile Include="VsDocument.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="VSPackage.resx">
<EmbeddedResource Update="VSPackage.resx">
<MergeWithCTO>true</MergeWithCTO>
<ManifestResourceName>VSPackage</ManifestResourceName>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CodeConverter\CodeConverter.csproj">
<Project>{7ea075c6-6406-445c-ab77-6c47aff88d58}</Project>
<Name>CodeConverter</Name>
</ProjectReference>
</ItemGroup>

<ItemGroup>
<Reference Include="System.Design" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup>
<PreBuildEvent>
</PreBuildEvent>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
4 changes: 2 additions & 2 deletions Vsix/source.extension.vsixmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<Tags>code converter vb csharp visual basic csharp net translate</Tags>
</Metadata>
<Installation>
<InstallationTarget Version="[17.8,18.0)" Id="Microsoft.VisualStudio.Community">
<InstallationTarget Version="[17.8,)" Id="Microsoft.VisualStudio.Community">
<ProductArchitecture>amd64</ProductArchitecture>
</InstallationTarget>
<InstallationTarget Version="[17.8,18.0)" Id="Microsoft.VisualStudio.Community">
<InstallationTarget Version="[17.8,)" Id="Microsoft.VisualStudio.Community">
<ProductArchitecture>arm64</ProductArchitecture>
</InstallationTarget>
</Installation>
Expand Down
Loading