dotnet / project-system

The .NET Project System for Visual Studio
MIT License
969 stars 387 forks source link

Custom Project Property Page not working on VS2022 #7776

Closed valentinbreiz closed 2 years ago

valentinbreiz commented 2 years ago

Visual Studio Version

Microsoft Visual Studio Community 2022 (64-bit) Version 17.0.1

Summary

Hello, is there any documentation about creating a custom project property page on Visual Studio 2022? The code used for VS2019 for the Cosmos project doesn't work anymore, the pages don't appear nor the custom icon in the solution explorer...

This issue has been moved from https://github.com/microsoft/VSExtensibility/issues/69.

@sayedihashimi @timheuer

Steps to Reproduce

  1. Install the Cosmos devkit
  2. Create a new Cosmos Kernel Project in Visual Studio
  3. Right click on project in Solution Explorer

Expected Behavior

Show the custom project property pages. A screenshot on how it used to be:

image

Actual Behavior

The pages doesn't appear and the Cosmos icon doesn't appear in the solution explorer.

drewnoakes commented 2 years ago

Hi @valentinbreiz, there is quite a bit of documentation on customising the Project Properties UI for various project types.

https://github.com/dotnet/project-system/tree/main/docs/repo/property-pages

You can find examples in this repo's code and PR/commit history.

valentinbreiz commented 2 years ago

Thanks for your response @drewnoakes, I found nearly everything I need. One of my problem now is changing the project icon in the solution explorer from a imagemanifest file. I succeed to change the icon using the KnownMoniker class, like here with a sample nuget icon:

image

But when I try to create an ImageMoniker from a .imagemanifest file, I have just nothing...

image

The code I'm using for the CosmosImages.imagemanifest:

<?xml version="1.0" encoding="utf-8"?>
<!-- This file was generated by the ManifestFromResources tool.-->
<!-- Version: 14.0.50929.2 -->
<ImageManifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/VisualStudio/ImageManifestSchema/2014">
  <Symbols>
    <String Name="Resources" Value="/Cosmos.VS.ProjectSystem;Component/Resources" />
    <Guid Name="MonikersGuid" Value="{4862ad45-3b62-4112-8dcd-cf2df64ff519}" />
    <ID Name="CosmosProjectRootIcon" Value="0" />
    <ID Name="Icon" Value="1" />
    <ID Name="Refresh_16x" Value="2" />
  </Symbols>
  <Images>
    <Image Guid="$(MonikersGuid)" ID="$(CosmosProjectRootIcon)">
      <Source Uri="$(Resources)/CosmosProjectRootIcon.png">
        <Size Value="16" />
      </Source>
    </Image>
    <Image Guid="$(MonikersGuid)" ID="$(Icon)">
      <Source Uri="$(Resources)/Icon.png">
        <Size Value="48" />
      </Source>
    </Image>
    <Image Guid="$(MonikersGuid)" ID="$(Refresh_16x)">
      <Source Uri="$(Resources)/Refresh_16x.png">
        <Size Value="16" />
      </Source>
    </Image>
  </Images>
  <ImageLists />
</ImageManifest>

and the code to create the ImageMoniker:

using System;
using Microsoft.VisualStudio.Imaging.Interop;

namespace Cosmos.VS.ProjectSystem
{
    internal static class CosmosImagesMonikers
    {
        private static readonly Guid ManifestGuid = new Guid("4862ad45-3b62-4112-8dcd-cf2df64ff519");

        private const int ProjectRootIconId = 0;

        public static ImageMoniker ProjectRootIcon => new ImageMoniker { Guid = ManifestGuid, Id = ProjectRootIconId };
    }
}

Is https://github.com/microsoft/VSProjectSystem/blob/master/doc/scenario/provide_custom_icons_for_the_project_or_item_type.md outdated for VS2022?

Edit: I'm also trying to call a method when a link is clicked. I found this in the documentation: https://github.com/dotnet/project-system/blob/main/docs/repo/property-pages/property-specification.md#callback-on-click But I don't really understand how to implement that. What is ILinkActionHandler and where can I find it? Do I have to declare a .xaml.cs file under my xaml rule file?

drewnoakes commented 2 years ago

@valentinbreiz the documentation on custom icons looks correct to me. I'm not an expert on the topic, but I would start by verifying how the content is registered within your VSIX. You can see an example of where an imagemanifest file was removed from this repo in https://github.com/dotnet/project-system/pull/6747/files. Perhaps that change will be useful to you.

As for ILinkActionHandler, it is defined in namespace Microsoft.VisualStudio.ProjectSystem.VS.PropertyPages.Designer in assembly Microsoft.VisualStudio.ProjectSystem.VS. To use it, you must provide a MEF export as shown in the documentation. It should just be a regular class in your assembly, and will be picked up by MEF from your package, provided your package is configured to provide MEF parts (via a Microsoft.VisualStudio.MefComponent in your VSIX manifest).

valentinbreiz commented 2 years ago

About the icon I think it may be an issue of Visual Studio because everything is done as here https://github.com/dotnet/project-system/pull/6747/files. The imagemanifest seems okay, the ImageMoniker too, the way I change the icon too because it works with KnownMonikers from Microsoft.VisualStudio.Imaging... It just fails to import my image. About my csproj I included the files like there too, I tried everything ahah. You can see my last csproj:

<Project Sdk="Microsoft.NET.SDK">

    <Import Project="$(BaseIntermediateOutputPath)*.nuget.g.props" Condition="'$(MSBuildProjectExtension)' == '.tmp_proj' OR $(MSBuildProjectName.EndsWith('wpftmp'))" />
    <Import Project="$(BaseIntermediateOutputPath)*.nuget.g.targets" Condition="'$(MSBuildProjectExtension)' == '.tmp_proj' OR $(MSBuildProjectName.EndsWith('wpftmp'))" />

    <PropertyGroup>
        <TargetFramework>net48</TargetFramework>
        <RuntimeIdentifier>win-x32</RuntimeIdentifier>
        <RootNamespace>Cosmos.VS.ProjectSystem</RootNamespace>
        <FileVersion>1.0.0.0</FileVersion>
        <AssemblyVersion>1.0.0.0</AssemblyVersion>
    </PropertyGroup>

    <PropertyGroup>
        <IncludeWpfReferences>True</IncludeWpfReferences>
        <IncludeWindowsFormsReferences>True</IncludeWindowsFormsReferences>
        <ExtensionInstallationRoot>Extensions</ExtensionInstallationRoot>
        <ExtensionInstallationFolder>Cosmos\ProjectSystem</ExtensionInstallationFolder>
        <GenerateResourceUsePreserializedResources>true</GenerateResourceUsePreserializedResources>
    </PropertyGroup>

    <ItemGroup>
        <Compile Remove="ProjectTemplates\**" />
        <Content Include="ProjectTemplates\**" IncludeInVSIX="True" />
        <Content Include="Resources\Icon.png" IncludeInVSIX="True" />
        <Content Include="Resources\CosmosProjectRootIcon.png" IncludeInVSIX="True" />
        <Resource Include="Resources\CosmosProjectRootIcon.png" />
        <Content Include="CosmosImages.imagemanifest" IncludeInVSIX="True" />
    </ItemGroup>

    <ItemGroup>
        <Content Include="BuildSystem\**" IncludeInVSIX="True" InstallRoot="MSBuild" VSIXSubPath="Cosmos\%(RecursiveDir)" />
    </ItemGroup>

    <ItemGroup>
        <XamlPropertyRule Include="BuildSystem\Rules\BootableConfiguration.xaml" />
        <XamlPropertyRule Include="BuildSystem\Rules\Content.xaml" />
        <XamlPropertyRule Include="BuildSystem\Rules\CosmosDebugger.xaml" />
        <XamlPropertyRule Include="BuildSystem\Rules\LaunchConfiguration.xaml" />
        <XamlPropertyRule Include="BuildSystem\Rules\PackageReference.xaml" />
        <XamlPropertyRule Include="BuildSystem\Rules\ResolvedPackageReference.xaml" />
        <XamlPropertyRule Include="BuildSystem\Rules\CosmosPropertyPage.xaml" />
    </ItemGroup>

    <ItemGroup>
        <None Update="BuildSystem\Rules\CosmosPropertyPage.xaml">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            <Generator>MSBuild:Compile</Generator>
        </None>
        <None Update="CosmosImages.imagemanifest">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            <Generator>MSBuild:Compile</Generator>
        </None>
    </ItemGroup>

    <!--
        WinForms
    -->
    <ItemGroup>
        <Reference Include="Microsoft.VisualBasic" />
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="Cosmos.Build.Common" />
        <PackageReference Include="Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime" Version="16.7.30328.74" />
        <PackageReference Include="Microsoft.VisualStudio.ProjectSystem.Analyzers" PrivateAssets="All" Version="15.8.243" />
        <PackageReference Include="Microsoft.VisualStudio.ProjectSystem.Sdk" Version="15.8.243" />
        <PackageReference Include="Microsoft.VisualStudio.Shell.15.0" Version="16.0.28729" />
        <PackageReference Include="Microsoft.VisualStudio.Shell.Interop.11.0" Version="16.10.31320.204" />
        <PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
        <PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.0.5232">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="System.Resources.Extensions" Version="5.0.0" />
        <PackageReference Include="VSPropertyPages" />
    </ItemGroup>

    <Target Name="IncludeMissingAssemblies" AfterTargets="GetVsixSourceItems" BeforeTargets="RemoveVSSDKAssemblies">
        <ItemGroup>
            <VSIXSourceItem Include="@(ReferenceCopyLocalPaths)" Condition="'%(Filename)' == 'Microsoft.Win32.Registry'" />
        </ItemGroup>
    </Target>

    <ItemGroup>
      <PackageReference Update="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" />
    </ItemGroup>
</Project>

I even tested with one test icon from the deleted ManagedImageMonikers with a png and a xml (included in the imagemanifest and csproj too) and I still have the same problem, no icon appearing like here:

image

Edit:

After checking, my png is in the vsix file:

image

jjmew commented 2 years ago

Closing the issue since the properties page question has been addressed. The rest is a VS Extensibility question. We can continue to use the issue for communication but we will keep it close since it is not related to the Project System

valentinbreiz commented 2 years ago

@jjmew do I have to submit a new issue for the Moniker problem in this repository or VS Extensibility?

drewnoakes commented 2 years ago

@valentinbreiz I cannot see anything wrong with the code you've posted. I see you have three icons in your manifest. Do either of the other two work as your project root icon? Can you try using a different icon file, in case there's something specific to that particular file. Do you see any messages logged in the debug output pane when debugging your extension?

You may have more luck asking this question of the VS Extensibility team. https://github.com/microsoft/VSExtensibility

softworkz commented 11 months ago

Custom images via imagemanifest got broken by recent VS updates. See here for more: https://developercommunity.visualstudio.com/t/VSSDKCPSExtensibility:-Image-Loading-i/10525678