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

Update component debugger to work for VS 2022 #896

Merged
merged 4 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<MicrosoftVisualStudioLanguageStandardClassificationVersion>16.8.239</MicrosoftVisualStudioLanguageStandardClassificationVersion>
<MicrosoftVisualStudioProjectSystemManaged>16.8.1-beta1-1008-05</MicrosoftVisualStudioProjectSystemManaged>
<MicrosoftVisualStudioProjectSystemManagedVS>16.8.1-beta1-1008-05</MicrosoftVisualStudioProjectSystemManagedVS>
<MicrosoftVisualStudioProjectSystemSDKTools>16.8.338-pre</MicrosoftVisualStudioProjectSystemSDKTools>
<MicrosoftVisualStudioRpcContractsVersion>16.9.23-alpha</MicrosoftVisualStudioRpcContractsVersion>
<MicrosoftVisualStudioSDKAnalyzersVersion>16.7.9</MicrosoftVisualStudioSDKAnalyzersVersion>
<MicrosoftVisualStudioShell150Version>16.7.30329.88</MicrosoftVisualStudioShell150Version>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8" ?>
<Rule Name="MyLaunchProfile"
Description="Allows a user to debug a Roslyn Component by running it in the context of another projects build."
DisplayName="Roslyn Component"
PageTemplate="commandNameBasedDebugger"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns="http://schemas.microsoft.com/build/2009/properties">

<Rule.Metadata>
<sys:String x:Key="CommandName">DebugRoslynComponent</sys:String>

<!-- KnownImageIds.ImageCatalogGuid -->
<sys:Guid x:Key="ImageMonikerGuid">AE27A6B0-E345-4288-96DF-5EAF394EE369</sys:Guid>

<!-- KnownImageIds.Execute -->
<sys:Int32 x:Key="ImageMonikerId">3644</sys:Int32>
</Rule.Metadata>

<Rule.DataSource>
<DataSource Persistence="LaunchProfile"
HasConfigurationCondition="False"
ItemType="LaunchProfile"/>
</Rule.DataSource>

<DynamicEnumProperty Name="targetProject"
DisplayName="Target Project"
Description="A project that uses this component, whose compilation will be debugged."
EnumProvider="TargetProjectEnumProvider" />

<StringProperty Name="Description"
Description="A Roslyn Component can be debugged in the context of compiling a second project that uses it. Ensure your target project is referencing this component for it to appear in the list.">
<StringProperty.DataSource>
<DataSource PersistedName="Description"
Persistence="ProjectFileWithInterception"
HasConfigurationCondition="False" />
</StringProperty.DataSource>
<StringProperty.ValueEditors>
<ValueEditor EditorType="Description" />
</StringProperty.ValueEditors>
</StringProperty>

</Rule>

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,5 @@ public LaunchSettingsManager(UnconfiguredProject owningProject, IDebugTokenRepla
}
return targetProject;
}

public void WriteProjectForLaunch(IWritableLaunchProfile profile, UnconfiguredProject targetProject)
{
if (profile is null)
{
throw new System.ArgumentNullException(nameof(profile));
}

if (targetProject is null)
{
throw new System.ArgumentNullException(nameof(targetProject));
}

var rootedPath = _owningProject.MakeRelative(targetProject.FullPath);
profile.OtherSettings[Constants.TargetProjectKeyName] = rootedPath;
}

}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,41 @@

using System;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.VisualStudio.ProjectSystem;
using Microsoft.VisualStudio.Utilities;

namespace Roslyn.ComponentDebugger
{
public static class ProjectUtilities
{
public static async Task<ImmutableArray<UnconfiguredProject>> GetComponentReferencingProjectsAsync(this UnconfiguredProject unconfiguredProject)
{
var targetProjects = ArrayBuilder<UnconfiguredProject>.GetInstance();

// get the output assembly for this project
var projectArgs = await unconfiguredProject.GetCompilationArgumentsAsync().ConfigureAwait(false);
var targetArg = projectArgs.LastOrDefault(a => a.StartsWith("/out:", StringComparison.OrdinalIgnoreCase));
var target = Path.GetFileName(targetArg);

var projectService = unconfiguredProject.Services.ProjectService;
foreach (var targetProjectUnconfigured in projectService.LoadedUnconfiguredProjects)
{
// check if the args contain the project as an analyzer ref
foreach (var arg in await targetProjectUnconfigured.GetCompilationArgumentsAsync().ConfigureAwait(false))
{
if (arg.StartsWith("/analyzer:", StringComparison.OrdinalIgnoreCase)
&& arg.EndsWith(target, StringComparison.OrdinalIgnoreCase))
{
targetProjects.Add(targetProjectUnconfigured);
}
}
}
return targetProjects.ToImmutableAndFree();
}

public static Task<ImmutableArray<string>> GetCompilationArgumentsAsync(this UnconfiguredProject project)
{
if (project is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,33 @@
<Nullable>enable</Nullable>
<UseWpf>true</UseWpf>
</PropertyGroup>
<ItemGroup>
<Page Remove="ComponentDebuggerLaunchProfile.xaml" />
<XamlPropertyRule Include="ComponentDebuggerLaunchProfile.xaml">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
<Generator>MSBuild:GenerateRuleSourceFromXaml</Generator>
<SubType>Designer</SubType>
<DataAccess>None</DataAccess>
<RuleInjection>None</RuleInjection>
</XamlPropertyRule>
</ItemGroup>
<Target Name="EmitAssemblyVersion" BeforeTargets="CoreCompile">
<WriteLinesToFile File="$(BaseIntermediateOutputPath)\AssemblyVersion.g.cs"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤢This is unpleasant, but required for the rules. It seems overkill to make it a generator, but I'm considering writing one to handle the whole rule injection which would remove a lot of the ceremony needed here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a source generator here. Nerdbank.GitVersioning might allow this to be automated without a source generator or project file changes.

@AArnott does NB.GV support setting the AssemblyVersion via the project file instead of the normal approach of automatically determining it from the repo history?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. NB.GV will steamroll any AssemblyVersion property you set with the discovered version.
If you wrote build authoring to execute your target in between GenerateAssemblyVersionInfo and GetBuildVersion then you could rewrite that property. But that strikes me as making your car float instead of building a boat.

Have you considered letting NB.GV do its thing? 😉

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use a SG

Overwrite="true"
WriteOnlyWhenDifferent="true"
Lines="namespace Roslyn.ComponentDebugger { internal static class AssemblyVersion { public const string Version = &quot;$(AssemblyVersion)&quot;%3B } }" />
<ItemGroup>
<Compile Include="$(BaseIntermediateOutputPath)\AssemblyVersion.g.cs" />
</ItemGroup>
</Target>
<ItemGroup>
<PackageReference Include="EnvDTE80" Version="$(EnvDTE80Version)" PrivateAssets="all" />
<PackageReference Include="EnvDTE90" Version="$(EnvDTE90Version)" PrivateAssets="all" />
<PackageReference Include="EnvDTE" Version="$(EnvDTEVersion)" PrivateAssets="all" />
<PackageReference Include="Microsoft.Internal.VisualStudio.Shell.Embeddable" Version="$(MicrosoftInternalVisualStudioShellEmbeddableVersion)" PrivateAssets="all" />
<PackageReference Include="Microsoft.VisualStudio.ProjectSystem.Managed" Version="$(MicrosoftVisualStudioProjectSystemManaged)" PrivateAssets="all" />
<PackageReference Include="Microsoft.VisualStudio.ProjectSystem.Managed.VS" Version="$(MicrosoftVisualStudioProjectSystemManagedVS)" PrivateAssets="all" />
<PackageReference Include="Microsoft.VisualStudio.ProjectSystem.SDK.Tools" Version="$(MicrosoftVisualStudioProjectSystemSDKTools)" PrivateAssets="all" />
<PackageReference Include="Microsoft.VisualStudio.Imaging" Version="$(MicrosoftVisualStudioImagingVersion)" PrivateAssets="all" />
<PackageReference Include="Microsoft.VisualStudio.Composition" Version="$(MicrosoftVisualStudioComposition)" PrivateAssets="all" />
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop" Version="$(MicrosoftVisualStudioShellInteropVersion)" PrivateAssets="all" />
Expand Down
24 changes: 24 additions & 0 deletions src/VisualStudio.Roslyn.SDK/ComponentDebugger/RuleExporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Microsoft.VisualStudio.ProjectSystem;
using Microsoft.VisualStudio.ProjectSystem.Properties;

namespace Roslyn.ComponentDebugger
{
internal static class RuleExporter
{
/// <summary>
/// Used to export the XAML rule via MEF
/// </summary>
[ExportPropertyXamlRuleDefinition(
xamlResourceAssemblyName: "Roslyn.ComponentDebugger, Version=" + AssemblyVersion.Version + ", Culture=neutral, PublicKeyToken=31bf3856ad364e35",
xamlResourceStreamName: "XamlRuleToCode:ComponentDebuggerLaunchProfile.xaml",
context: PropertyPageContexts.Project)]
[AppliesTo(Constants.RoslynComponentCapability)]
#pragma warning disable CS0649
public static int LaunchProfileRule;
#pragma warning restore CS0649
}
}
Loading