codemaid icon indicating copy to clipboard operation
codemaid copied to clipboard

Visual Studio 2022 Support

Open scottkuhl opened this issue 5 years ago • 38 comments

Installed product versions

  • Visual Studio: 2022 All Versions

Description

Make the extension available in Visual Studio 2022.

Steps to recreate

  1. Download the extension installer.
  2. Run the installer.

Current behavior

Message that it is already installed to all applicable products appears even though it is not installed in Visual Studio 2022. It is also not listed in Online Extensions in Manage Extensions Visual Studio 2022.

Expected behavior

Installs and works in Visual Studio 2022.

Note: Sorry for the all the extra details. I probably could have stopped with the title on this one.

scottkuhl avatar Jun 17 '21 20:06 scottkuhl

Also looking for this 🙂

Eli-Black-Work avatar Jun 18 '21 06:06 Eli-Black-Work

Guess we can tell who the early adopters are, haha XD

Eli-Black-Work avatar Jun 18 '21 06:06 Eli-Black-Work

There is already a PR for this #817

wertzui avatar Jun 22 '21 07:06 wertzui

Thanks all for jumping on this quickly. There are indeed some compatibility breaking changes in VS2022. I believe last I heard it was expected that for all extensions the code would have to be branched and separate releases made targeting different versions of Visual Studio. For the time being I would keep the dev and release branches pointing to the existing VS2017/VS2019 version, tied into the CI pipeline, etc. We'll end up creating a new vs2022 branch and I'm still thinking about the other implications.

It looks like 2 PRs have started, #817 and #818. It looks like #818 might have gone farther with following recommendations. Thanks for links @scottkuhl as there may be some non-obvious changes we need to make to support the changes. Testing those out and seeing what issues come up (e.g. the settings dialog not opening in one) is super helpful and appreciated. <3

codecadwallader avatar Jun 23 '21 11:06 codecadwallader

Hey all, I've been working on the VS2022 upgrade. I decided to start fresh on a new vs2022 branch and follow the instructions for multi-targeting VS versions based on https://docs.microsoft.com/en-us/visualstudio/extensibility/migration/update-visual-studio-extension?view=vs-2022 vs. building on top of #818 which is VS2022-only. I have to say these are far more detailed instructions than have ever been provided before and I really appreciate them.

What is done

  • "Modernize your projects". I attempted this a few years ago and encountered several issues at the time. This worked pretty smoothly this time around and closes #643. CodeMaid still worked as expected at this checkpoint.

  • Created a shared project called CodeMaidShared, migrated code and linked resources. Deviations: -- I haven't done the same with CodeMaid.IntegrationTests yet. I wanted to prove it out with the main project first. -- Instead of moving all the resource files and having both projects utilize links to the new location, I left all files in their original location and only have the new project performing links. This seems like it should(tm) be the same difference to me and saved a chunk of effort.

  • Created the new VS2022 VSIX called CodeMaid.VS2022 with necessary links/updates.

  • VS2017 can compile and generate the original CodeMaid VSIX successfully.

  • VS2022 can compile and generate the new CodeMaid 2022 VSIX successfully.

  • i.e. the migration instructions above are complete.

Where it stands

The extension loads successfully into the VS2022 Preview IDE, but that's about it. Some very limited functionality is working (e.g. build progress tool window) but most core functionality is not working for different reasons.

Cleaning/Joining

System.NotImplementedException is thrown when trying to use the EnvDTE.TextDocument.ReplacePattern API. I'm curious if this is related to switching from explicit EnvDTE references to the general Microsoft.VisualStudio.SDK package and if it's not targeting the correct version or needs an explicit binding redirect.

Digging

FileNotFoundException: Could not load file or assembly 'SteveCadwallader.CodeMaid, Culture=neutral' or one of its dependencies. The system cannot find the file specified. I'm curious if this is related to switching to a shared project and the XAML references are not working as expected. The same issue happens for other UI dialogs (e.g. Options and About dialogs).

Reorganizing

System.NotImplementedException is thrown when trying to use the EnvDTE.EditPoint.FindPattern API. This is very similar to above.

What is next

I'll be reaching out to Microsoft to see if they can provide any technical guidance on those issues. I'm sure we can work through them but if they have any hints that would certainly help. The vs2022 branch is published and I will gladly accept PRs against it.

codecadwallader avatar Jul 30 '21 21:07 codecadwallader

An update:

I've been working with Microsoft on some of the issues above. I think we've got the Digging issue figured out but unfortunately with Preview 3.1 I'm no longer able to get the extension to load (i.e. a step backwards) so I haven't been able to test it.

The current error:

 <entry>
    <record>2198</record>
    <time>2021/09/03 12:14:20.645</time>
    <type>Error</type>
    <source>VisualStudio</source>
    <description>SetSite failed for package [CodeMaidPackage]Source: &apos;SteveCadwallader.CodeMaid&apos; Description: Method not found: &apos;Void EnvDTE._dispBuildEvents_OnBuildBeginEventHandler..ctor(System.Object, UIntPtr)&apos;.&#x000D;&#x000A;System.MissingMethodException: Method not found: &apos;Void EnvDTE._dispBuildEvents_OnBuildBeginEventHandler..ctor(System.Object, UIntPtr)&apos;.&#x000D;&#x000A;   at SteveCadwallader.CodeMaid.CodeMaidPackage.&lt;RegisterEventListenersAsync&gt;d__36.MoveNext()&#x000D;&#x000A;   at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[TStateMachine](TStateMachine&amp; stateMachine)&#x000D;&#x000A;   at SteveCadwallader.CodeMaid.CodeMaidPackage.RegisterEventListenersAsync()&#x000D;&#x000A;   at SteveCadwallader.CodeMaid.CodeMaidPackage.&lt;InitializeAsync&gt;d__32.MoveNext() in C:\src\codemaid\CodeMaidShared\CodeMaidPackage.cs:line 202&#x000D;&#x000A;--- End of stack trace from previous location where exception was thrown ---&#x000D;&#x000A;   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()&#x000D;&#x000A;   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&#x000D;&#x000A;   at Microsoft.VisualStudio.Shell.AsyncPackage.&lt;&gt;c__DisplayClass20_0.&lt;&lt;Microsoft-VisualStudio-Shell-Interop-IAsyncLoadablePackageInitialize-Initialize&gt;b__1&gt;d.MoveNext()&#x000D;&#x000A;--- End of stack trace from previous location where exception was thrown ---&#x000D;&#x000A;   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()&#x000D;&#x000A;   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&#x000D;&#x000A;   at Microsoft.VisualStudio.Threading.JoinableTask.&lt;JoinAsync&gt;d__76.MoveNext()</description>
    <guid>{4C82E17D-927E-42D2-8460-B473AC7DF316}</guid>
    <hr>80131513</hr>
    <errorinfo></errorinfo>
  </entry>

While I'm waiting to hear back if anybody has ideas I'm all ears. Also if you want to play around the vs2022 branch is available. We'll get there!

codecadwallader avatar Sep 03 '21 12:09 codecadwallader

@codecadwallader Did you manage to work out the error you mentioned above? Would love to know the progress on this.

kotx avatar Sep 19 '21 19:09 kotx

I recently started using VS2022 Preview 4 and I am really missing the "Find in Solution Explorer" feature. I'm really hoping CodeMaid gets enabled soon.

TonyValenti avatar Sep 23 '21 11:09 TonyValenti

I recently started using VS2022 Preview 4 and I am really missing the "Find in Solution Explorer" feature. I'm really hoping CodeMaid gets enabled soon.

There is a built in Hotkey for that. On my German system it is CTRL + ß, s On English systems, it should be CTRL + [, s according to https://stackoverflow.com/a/55025095/1378307

wertzui avatar Sep 23 '21 12:09 wertzui

@kotx I did get through the SetSite error. It was actually just user error on my part, wrong startup project selected 🤦

I'm making progress on issue 2 (UI resolution using a shared project) but it's still in back and forth with Microsoft. It will mean refactoring the paths for a number of items but in particular trying to set the Application.ResourceAssembly which seems to be needed in shared contexts is not working as expected and provides the following error message:

IOException: Assembly.GetEntryAssembly() returns null. Set the Application.ResourceAssembly property or use the pack://application:,,,/assemblyname;component/ syntax to specify the assembly to load the resource from.

I haven't made any headway on related issues 1 and 3 about not implemented APIs. I've been hoping newer preview editions would catch up and fill out more of the API but as of Preview 4.1 they are still not implemented.

It's slow going, but continuing to work on it and as always help is welcome!

codecadwallader avatar Sep 24 '21 12:09 codecadwallader

A lot of the challenge we're running into is trying to switch to a new shared project infrastructure in order to support both VS2017/VS2019 and VS2022 which introduces breaking compatibility changes. I still think this is the right way to go going forwards and is the recommended and documented path too, however a shortcut could be a direct upgrade to a VS2022-only version of CodeMaid. This would only be in a branch and would get abandoned eventually. It would be interesting to see if it encountered some of the same API issues or if they were only an issue with the shared project approach.

codecadwallader avatar Sep 28 '21 12:09 codecadwallader

Status update: it looks like we've got issue 2 (UI resolution) worked out thanks to some help from Microsoft. 🎉 We needed to utilize Assembly.GetExecutingAssembly vs. GetEntryAssembly and the timing was off for when we were adding it. This seems to be required for VS2022 only, VS2017 doesn't need it but also doesn't seem to be harmed by it in some quick regression testing.

So what that all of the UI elements are appearing! The Spade (digging) window is not showing any content yet because while the code model is building successfully when we go to find the regions (not a part of the code model) the same missing API FindPattern that is issue 1 and 3 is used and throws an error.

I'm continuing to work with them and all the latest changes are pushed up into the vs2022 branch for anyone who would like to explore.

codecadwallader avatar Oct 07 '21 12:10 codecadwallader

I got a VS2022 survey and I said it was a no-go because it is missing code maid.

TonyValenti avatar Oct 07 '21 23:10 TonyValenti

I can't wait till this is finished, great work out there, code maid has been a MUST for me for years now .

NaserArab avatar Oct 12 '21 19:10 NaserArab

I'm very much interested in this one, glad it is already being worked upon, thank you all!

plarpoon avatar Oct 14 '21 13:10 plarpoon

Good news status update:

#847 was made by @olegtk to handle the FindPattern/ReplacePattern APIs not being supported in VS2022. These weren't listed as removed APIs so I've opened this issue in the docs: https://github.com/MicrosoftDocs/visualstudio-docs/issues/7148

There is a newer IFindService that was introduced with VS2019 which is now used instead. This migration by @olegtk was a huge help as find/replace is a pretty core pattern and was blocking a lot of functionality. This is a pretty significant change so some regression testing eyes would be greatly appreciated.

We'll have to drop support for VS2017 with the next release since there isn't an API that works from VS2017-VS2022. I haven't updated the code base yet with making VS2019 the minimum required version but this will be CodeMaid v12 with VS2019+VS2022 support.

I'm also planning to drop the integration tests. They haven't worked since pre-VS2017 (see #467 for details) and it doesn't make sense to migrate them to the new shared project structure if they won't work anyways. It's a bummer and I'm hopeful to bring them back from the source control archives some day if they become supported again.

I'm very happy to say we've got an initial version that is available for alpha testing with VS2022 only:

CodeMaid.VS2022.20211014T145200.vsix.zip

This will have to be manually installed and uninstalled to VS2022 since it is out of band. Some new CI/CD pipeline updates will need made since VS2019 and VS2022 will have to compile/install separately.

If you like to live dangerously and would like to help out with testing this version out it would be greatly appreciated! As you encounter issues please spin up new GitHub issues and clearly indicate that it is for VS2022 (part of the issue template).

Thanks all for the help and enjoy!

codecadwallader avatar Oct 14 '21 15:10 codecadwallader

Just installed the Alpha on my VS2022. The primary features I've been missing (Find in solution explorer, Reorganze and Cleanup) are all working perfectly. This is fantastic, keep up the good work!

screaney avatar Oct 14 '21 16:10 screaney

What a wonderful new! I was looking forward to it! I'm a big fan of the "Ctrl+M, Space" cleanup shortcut. I've been testing it here... and from what I can see it's not working with .razor files

pierrebrito avatar Oct 14 '21 16:10 pierrebrito

@pierrebrito was it working with .razor files in VS 2019? I just tried and seems not to me.

olegtk avatar Oct 17 '21 07:10 olegtk