Jump to content

VS 2022 Template for .NET 5.0


Recommended Posts

@Ego Eram Reputo

In my thirst for knowledge, I came across this old thread that provides a walkthrough using VS to create a plugin.

 https://forums.getpaint.net/topic/25828-help-needed-using-visual-studio-instead-of-codelab-for-developing/

 

If you can believe it - your template still works in Visual Studio 2022 Preview.

I took the liberty of editing the walkthrough to reflect the changes since VS Express. I am also able to describe some of the headaches I have been having on my learning curve.

Perhaps we can rebuild this thread with tips on how to use VS 2022 Preview to build plugins. Here is the (edited) version of your walkthrough with my comments and questions added.

 

Spoiler

Setting the template up

1. Download VS template below (I've updated the references and added some notes).

2. Move the template to the correct directory (e.g. C:\Users\Andrew\Documents\Visual Studio 2022\Templates\ProjectTemplates\).  Don't unzip it (as per the original instructions).

Customizing the setup - just for your plugin

3. Open VS  (I'm using Visual Studio 2022 Preview in order to use net 5.0).

4. Select Create New Project from the right hand pane.

5. Select the Plugin Template - updated Dec2010 with a single click. (Enter 2010 in search box to locate). Click next

6. Type in your plugin name.  This is important as the plugin namespace is derived from the project name.  Just save yourself the grief.

7. Click create to open the template which will automatically name some aspects for you.

8. Save the project immediately.  File > Save "Project Name".

9. Right Click Project name and select properties.  Application tab appears.

10. Change Target Framework to .NET 4.8 (not 3.5 Client Profile). A message will come up saying the current project needs to be closed.
Select Yes. (At this point I wonder why I don't get to select Net 5.0) When I create a new project I have that option so I know it is installed.

Right click on Project and select unload. Double click to open *.csproj file. This is where I have questions about changing the version references to all the old code. For now I will just continue with the walkthrough.

11. Save again then close the solution and reopen.  This is usually required when the framework is changed.  Best just to do it.

12. Double click the Resources entry in the Solution Explorer.  Right click on .png file and select open with. A popup will appear asking to open with. You may have to add paintdotnet.exe to your list of choices. The one supplied is the one I used for WhichSymbol+. 

13. Save finished icon & return to VS. 

14. Open EffectPlugin.cs by double clicking it in Solution Explorer.

15. Find phrase "Plugin name here" and insert your plugin name.  Quotes are required.

 

VS finds one error. Line 143  My solution - Add Reference System.Drawing.Common, version5.0 / This creates another error on line 30
My solution remove System.Drawing / this creates three more errors Line 9, 53,55 and 59.  Closed and reopened back to the one error. Proper fix required.

 

Code that is in error;
 : base(EffectPlugin.StaticName, EffectPlugin.StaticImage, EffectPlugin.StaticSubMenuName, EffectFlags.Configurable)

 

16. Set the menu that the plugin should appear in.  Some samples are included to get you started.  I'd generally use the SubmenuNames.Render option rather than the return null option. Render sub-menu name is used as an example.

 

17. Return to the Project > project name Properties > Application tab.  Delete the Assembly Name and substitute your own.  Make sure it has no spaces in it.

18. Click on the Assembly Information button in the same tab.   Update title, Description and Copyright info as required.  OK.

 

OLD 19. Open the Build Events tab and check the path to Paint.NET is correct.  This copies the built effect directly to the Paint.NET/effects directory.  FOR FUTURE REFERENCE >> In between builds you need to delete the old *.dll file and close Paint.NET.

 

New 19. Select Debug tab - change to "Start external program" - 
Enter command line to start Paint.NET IE: C:\Program Files\Paint.Net\Paintdotnet.exe
Does working directory need to be filled? If so I just use C:\Program Files\Paint.Net\
Click Enable native code debugging

 

20. Save project.

 

Build just builds the project. Debug is used to create the *.dll

This is the error I get when trying to build. Related to error in Step 15.

Severity    Code    Description    Project    File    Line    Suppression State
Error    CS1705    Assembly 'PaintDotNet.Effects' with identity 'PaintDotNet.Effects, Version=4.300.7918.1291, Culture=neutral, PublicKeyToken=null' uses 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version than referenced assembly 'System.Runtime' with identity 'System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'    StarryNight    C:\Users\Andrew\Desktop\Training\StarryNight\CSC    1    Active


I will stop here until I can resolve that error. I have debugged a few plugins successfully and can finish off the walkthrough when I get that error resolved. My how things have changed for the next three steps.

 

20.  Build project (F6).  The post-build copy should drop the *.dll into the correct PDN folder.  Open PDN and see if the plugin appears.

(If the build fails with an error in "resx" file, change the icon reference in the resx file to 2.0.0.0).

21. If the dll builds successfully with no errors and is in Pdn/effects folder ok, but the effect does not show up in the PDN menu. Try building it without an Icon i.e. 'return null' to see if that is where the problem lies.

22. Return to the EffectPlugin.cs file (it should be a tab on the main window).  Scroll to the bottom of the file and you'll find the Render method.  This is where the heart of your plugin should go.   See where it says // Render code Here  - bung your code in there!


I envision adding code snippets to this thread to provide addition help in building a plugin. They are spread all over the place. Your help would be appreciated :)

 

 

 

Edited by AndrewDavid
  • Upvote 1

qG3vze.png

 

Link to comment
Share on other sites

The Icon needs to be 16 by 16 .png (NOT an icon filetype). Right-click on the icon and select 'open with'... then navigate to your copy of Pdn. Then it should open up Pdn for editing.

Do you have EER's VS Plugin Template Pdf ? ... slightly out of date now (2013) but still very useful, slightly more detailed than the instructions in that thread. The instructions for adding and embedding .sample images in the Plugin Browser thread are useful too.
Perhaps @E.E.R. has a more up to date copy of the .Pdf he could share with you? ( I would share my copy but would need Scott's permission).

Switching from codelab to Visual studio is not easy!!! - The simplest errors are daunting when you start (still are for me sometimes!).
You're doing well - good luck.

 

//Try this:
  public YourEffectPlugin()// whatever you've called your effect
            // : base(StaticName, StaticImage, SubmenuNames.Render, EffectFlags.Configurable)- this is the old code!
            : base(StaticName, StaticIcon, SubmenuNames.Render, new PaintDotNet.Effects.EffectOptions() { Flags = EffectFlags.Configurable })//This is the new code. Use whichever SubmenuNames category is appropriate
        {
        }

 

 

Red ochre Plugin pack.............. Diabolical Drawings ................Real Paintings

 

PdnForumSig2.jpg

Link to comment
Share on other sites

The icon can actually be any square size. It will be scaled to the appropriate size at display time.

 

This permits you to use, for example, a 32x32 icon so that it still looks good on a high-DPI screen.

 

I believe @BoltBait and @toe_head2001 make use of this for CodeLab.

  • Thanks 1
  • Upvote 1

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

@Red ochre Thank you for your input

 

Tried your suggestion. Had to change to:

            : base(StaticName, StaticImage, SubmenuNames.Render, new PaintDotNet.Effects.EffectOptions() { Flags = EffectFlags.Configurable })

but it still did not clear error. Still getting prompted to add reference to System.Drawing.Common that leads to more errors.

 

Walkthrough changed to read

12. Double click the Resources entry in the Solution Explorer.  Right click on .png file and select open with. A popup will appear asking to open with. You may have to add paintdotnet.exe to your list of choices. The one supplied is the one I used for WhichSymbol+. 

 

 

Edited by AndrewDavid

qG3vze.png

 

Link to comment
Share on other sites

First to say, I have no experience using VS 2022 Preview but there may be no difference to VS 2019 which I'm using.

 

You can right click your project in the SolutionExplorer and select 'Edit Project File'. Save will then adapt your dependencies.

 

What's the content of you project file? Does it contain the following PropertyGroup?

  <PropertyGroup>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>

This will add Microsoft.WindowsDesktop.App.WindowsForms to Dependencies->FrameWorks

 

You should also see the references to the paint.net dlls there. I.e.

  <ItemGroup>
    <Reference Include="PaintDotNet.Base">
      <HintPath>..\..\..\..\Users\YOUR LOGIN NAME\Downloads\paint.net.4.300.7918.1291.portable.x64.scd.aot\PaintDotNet.Base.dll</HintPath>
    </Reference>
    <Reference Include="PaintDotNet.Core">
      <HintPath>..\..\..\..\Users\YOUR LOGIN NAME\Downloads\paint.net.4.300.7918.1291.portable.x64.scd.aot\PaintDotNet.Core.dll</HintPath>
    </Reference>
    <Reference Include="PaintDotNet.Data">
      <HintPath>..\..\..\..\Users\YOUR LOGIN NAME\Downloads\paint.net.4.300.7918.1291.portable.x64.scd.aot\PaintDotNet.Data.dll</HintPath>
    </Reference>
  </ItemGroup>

You may change the relative references to fixed ones (to avoid problems if you are moving the project folder).

 

 

midoras signature.gif

Link to comment
Share on other sites

2 hours ago, AndrewDavid said:

Because the template was originally designed in 3.5 , that file is in a totally different format. Any changes to it crashes the whole project.

But thanks for trying :)

 

I do have a question, is there any issue with exporting to vs project via codelab? That's what I do.

G'MIC Filter Developer

Link to comment
Share on other sites

44 minutes ago, Reptillian said:

I do have a question, is there any issue with exporting to vs project via codelab? That's what I do.

 

CodeLab currently generates the .csproj file in the legacy format.

However, the next version of CodeLab will generate the .csproj file in the newer MSBuildProjectSDK format.

 

If you want to convert older .csproj files to the newer format, you can use try-convert.

 

Does that answer your question?

  • Like 1
Link to comment
Share on other sites

15 hours ago, AndrewDavid said:

@Ego Eram Reputo

In my thirst for knowledge, I came across this old thread that provides a walkthrough using VS to create a plugin.

 https://forums.getpaint.net/topic/25828-help-needed-using-visual-studio-instead-of-codelab-for-developing/

 

If you can believe it - your template still works in Visual Studio 2022 Preview.

 

Dang - I wrote that nine years ago 🤯 I am quite shocked the template & guide still work.

 

I'm glad you found it a little bit helpful. I've chosen to stop updating the walkthrough as @toe_head2001's templates are much more up to date. Second reason - I'm not the programmer people think I am. Oh I've dabbled a bit, but being entirely self taught my bad habits and poor assumptions are legion.

 

BoltBait deserves most of the credit for that guide. I followed his suggestions and did what you did above - I recorded the steps I took to make it work.

 

As I've no plan to continue working on that template & guide - feel free to republish it with your updated comments. I am happy to make my last version of the template available if you would like a copy (dated 2019).

 

Link to comment
Share on other sites

Thanks for replying @Ego Eram Reputo

@Red ochre mentioned you had a PDF around somewhere. Do you?

Here's where I'm at. I have now successfully converted the VS file to Net 5.0 using @toe_head2001's suggested try-convert method. My goal is not to create a plugin but rather describe the steps to load a working template into VS2022 (Preview). A couple(4) of command lines are now showing errors that I cannot resolve. This prevents me from building and/or debugging the project. I don't expect it to do anything, I just want to document the steps.  I will upload it to GitHub for help in resolving those 4 errors. I know they say the commands are obsolete, but when I take them out, it just creates more errors. If I can resolve the errors, I could also push it out as a template.

https://github.com/AndrewDavid007/StarryNight

qG3vze.png

 

Link to comment
Share on other sites

Link to comment
Share on other sites

6 hours ago, AndrewDavid said:

Because the template was originally designed in 3.5 , that file is in a totally different format. Any changes to it crashes the whole project.

But thanks for trying

 

I would then start with a fresh one and add the code to this. It's much more difficult to adapt old ones.

 

 

 

 

 

midoras signature.gif

Link to comment
Share on other sites

55 minutes ago, AndrewDavid said:

A couple(4) of command lines are now showing errors that I cannot resolve.

 

Paste them here.

Link to comment
Share on other sites

@Ego Eram Reputo As you wish;

Line 30
       public static Bitmap StaticImage { get { return Properties.Resources.Icon; } }

Line 42
           : base(EffectPlugin.StaticName, EffectPlugin.StaticImage, EffectPlugin.StaticSubMenuName, EffectFlags.Configurable)

Line 49
           return new EffectPluginConfigDialog();

Line 54
            PdnRegion selectionRegion = EnvironmentParameters.GetSelection(srcArgs.Bounds);

 

Keep in mind - If you say they are obsolete - deleting them creates more errors. Best to see it by downloading the repository.

qG3vze.png

 

Link to comment
Share on other sites

Line 54

            PdnRegion selectionRegion = EnvironmentParameters.GetSelectionAsPdnRegion();

 

That's the easy one ;)

 

Link to comment
Share on other sites

14 minutes ago, AndrewDavid said:

Keep in mind - If you say they are obsolete - deleting them creates more errors. Best to see it by downloading the repository.

Obsolete just means you have to use an other variant and not just to remove something.

 

EffectFlags.Configurable => new EffectOptions() { Flags = EffectFlags.Configurable }

midoras signature.gif

Link to comment
Share on other sites

@Ego Eram Reputo Well done :) 

3 to go - Is it safe to assume they need to be corrected in the template? I need to take notes.

Your PDF is most excellent. It provides more steps than I could imagine. It really bridges a number of gaps I was missing regarding custom controls. I know what I'll be doing tomorrow. I may have to start all over again, but I don't mind. Too much time on my hands and still quarantined.

qG3vze.png

 

Link to comment
Share on other sites

@AndrewDavid it looks like you made some manual changes to the .csproj that are not correct.  There's also a ton of extra junk in there.

 

In it's entirety, the .csproj for this project should look like this:

Spoiler
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net5.0-windows</TargetFramework>
    <OutputType>Library</OutputType>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="PaintDotNet.Base">
      <HintPath>..\..\..\..\..\..\..\Program Files\Paint.NET\PaintDotNet.Base.dll</HintPath>
    </Reference>
    <Reference Include="PaintDotNet.Core">
      <HintPath>..\..\..\..\..\..\..\Program Files\Paint.NET\PaintDotNet.Core.dll</HintPath>
    </Reference>
    <Reference Include="PaintDotNet.Data">
      <HintPath>..\..\..\..\..\..\..\Program Files\Paint.NET\PaintDotNet.Data.dll</HintPath>
    </Reference>
    <Reference Include="PaintDotNet.Effects">
      <HintPath>..\..\..\..\..\..\..\Program Files\Paint.NET\PaintDotNet.Effects.dll</HintPath>
    </Reference>
  </ItemGroup>
  <PropertyGroup />
  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="copy &quot;$(TargetFileName)&quot; &quot;C:\Program Files\Paint.NET\Effects&quot;" />
  </Target>
</Project>

 

 

Link to comment
Share on other sites

@toe_head2001 Go back and see the original template. That's where it came from. Don't think I would know all those garbage entries.

<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">

I remember adding one "<EnableDefaultCompileItems>false</EnableDefaultCompileItems>" to resolve a build error.

I wonder if all that code signifies a template, not a working plugin. The more code I see - the more code I learn.

Just shows how much things have changed. :)

 

qG3vze.png

 

Link to comment
Share on other sites

16 minutes ago, toe_head2001 said:

You should not use it anyway.

 

Just following the inteliSense. The other option was to remove 2 of the .cs files. After looking at @Ego Eram Reputo's and your PDF I have a lot of review ahead of me.

After resolving those last two errors, I can delete the cs files and see what happens when I remove EnableDefaultCompileItems and try to build.

qG3vze.png

 

Link to comment
Share on other sites

@AndrewDavid I'll upload the PDF source document to Google Docs tonight.

 

PM me your email address so I can share it with you. That way you can make changes and additions directly to the document.

Link to comment
Share on other sites

@Ego Eram Reputo No need. I don't have Adobe. I do have Paint though. It imported very well. All 41 pages. I've got 10 pages done already.

I'll zip up the PDN and let you create the Adobe document if that works. Maybe just leave it in PDN format? There are procedures there I have never tried yet.

Maybe I'm not familiar with editing the online version. do I need Adobe? I'll think of the PDN as a draft.

qG3vze.png

 

Link to comment
Share on other sites

  • AndrewDavid changed the title to VS 2022 Template for .NET 5.0

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...