back

Visual Studio for SimHub plugin:  How-To

SimHub and its plugin SDK are in C#;
W3 C# Tutorial describes C# elements well;
content until C# Methods is classic C.
tutorialspoint Basic Syntax page lists C# Keywords;
Program Structures page introduces Visual Studio
sadly employing concepts out of order or simply unexplained.


Visual Studio 2019 does not update to 2022;  VS 2022 installs in parallel.
(VS Community 2022 Installation)

Clicking on a .csproj file launched Visual Studio
  • should really click on .sln file;  a solution may contain multiple projects...
        .csproj file was listed in lower right Properties window
  • clicked on wrench icon, launching an Application window,
        which showed .NET framework 4.7.2
        - SimHub wants at least 4.8, per Wotever 8.2.0 release 12/16/2022
          Change framework setting in Visual Studio

    SDK-style projects enable removing unused resources.
    Unlike legacy Visual Studio .NET Framework projects,
    .NET uses SDK-style project files,
    but does NOT support WPF applications, only console.
    Migrating .NET Framework WPF to .NET involves converting projects;
    see porting overview and upgrading HowTo.
    for VS 2022
    • VS community already at v 17.8.0
    • install the .NET Upgrade Assistant from inside Visual Studio
    • Launched Full Assessment with Porting Assitant from Extensons
      after setting .Net 7, but it hung...
    • Exitted VS and updated it to 17.8.1; uninstalled Porting Assitant
    • Ran In-place project upgrade to .NET 8.0;
      many VS errors in SettingsControlDemo.xaml for <styles;..
    • The plugin uses XAML; .NET 8 conversion broke it.
    • Reverted "update" using GitHub Desktop
      VS complained about TargetFrameworkVersion presumably based on cached information.
      Solved by moving the project, then VS offered to forget about it.

    for VS 2019

    Converting old csproj to SDK

    This succeeded only because no XAML user interface code.
    SDK projects are wanted for unused reference removal support.
    >dotnet tool install --global Project2015To2017.Migrate2019.Tool
    You can invoke the tool using the following command:  dotnet-migrate-2019
    Tool 'project2015to2017.migrate2019.tool' (version '4.1.3') was successfully installed.

    >dotnet migrate-2019 wizard E:\my\Sim\SimHub\SimHub\PluginSdk\MIDIio\MIDIio.csproj
    (transcript)

    Since the dotnet migrate-2019 wizard was run on the .csproj file but not the .sln,
    Clicking the .csproj file launched VS, and unused references were removed,
    but .sln was not updated.
    As a test, that .sln was disappeared by moving to another directory,
    and Visual Studio seemed fine with no .sln file.
    However, moving the .sln file back while it was running
    excited Visual Studio enough to update it.

    Because SDK version defaults to OutDir ..\..\net48\,
    added to .csproj file:  <OutDir>..\..\</OutDir>

    A simple SimHub plugin
    https://github.com/search?q=simhub+plugin
    https://github.com/viper4gh/SimHub-Plugin-CalcLngWheelSlip
    Has (for VS):
    Properties/, *.cs project.class.sln,csproj, SettingsControl.xaml, xaml.cs
    (for git):  .gitattributes, .gitignore
    Also:  README.md, docs/
    Cloned by GitHub Desktop to SimHub/PluginSdk/
    launched with VS 2019,
    with Viper.PluginCalcLngWheelSlip highlighted under Solution Explorer,
    click wrench icon under Properties to launch main properties.
    Under Debug, added * Start external program:  [\path\to\SimHubWPF.exe  ]
    .. a relative path (..\..\SimHubWPF.exe) was rejected.
    That provokes creation of Viper.PluginCalcLngWheelSlip.csproj.user
    .. which was ignored by .gitignore entry '*.user'
    $ git add -f Viper.PluginCalcLngWheelSlip.csproj.user
    Build failed, in part complaining about .NET Target framework not 4.8
    - downloaded and installed, then under Properties wrench Application,
    changed Target framework to .NET Framework 4.8
    .. which modified Viper.PluginCalcLngWheelSlip.csproj

    Forked in GitHub Desktop, which pushed it to
    https://github.com/blekenbleu/SimHub-Plugin-CalcLngWheelSlip
    ... renamed on GitHub website under settings
    https://github.com/blekenbleu/CalcLngWheelSlip

    Project then built with warning:
    >E:\my\Sim\SimHub\SimHub\PluginSdk\CalcLngWheelSlip\PluginCalcLngWheelSlip.cs(13,6,13,22):
      warning CS0612:  'PluginDescritionAttribute' is obsolete


    deleted PluginDescritionAttribute, which Wotever had deprecated

    Prompted for IntelliCode;  opted in.
    At this point, GitHub Desktop expects push to https://github.com/blekenbleu/SimHub-Plugin-CalcLngWheelSlip
    ... but automagically accommodated repository name change.
    commented out '*.user' in .gitignore to push Viper.PluginCalcLngWheelSlip.csproj.user

    The Viper.PluginCalcLngWheelSlip plugin not only built,
    it installed and was detected by SimHub and seems to work,
    but not in iRacing or ACC...
    SimHub.Logging:  [2023-01-16 16:34:32,492] INFO - Initialising Viper.PluginCalcLngWheelSlip.ViperDataPlugin plugin
    Exception thrown:  'System.IO.FileNotFoundException' in mscorlib.dll
    Using this for renaming DataPluginDemo to MIDI-io turned everything to crap:
    Optional Step:  Rename Namespaces should emphasize that requires loading a .cs file... got this warning:

    VS rejects MIDI-io namespace;
    MIDIio is OK...Some brute force Vim, then try renaming per above instructions.
    One gotcha:  rename the whatever before right-clicking for rename
    Can't find resource mahapps.styles.button.flat
    Fiddling with resources provoked license complaints from (Arduino) Visual Micro, so uninstalled it.
    Despite warning, manually changed Properties/AssemblyInfo.cs,
    replacing blekenbleu.PluginSdkDemo with MIDIio

    Hyphen in namespace is rejected;  probably also in class names.
    Using MIDIio for both namespace and class is evidently very bad, halting VS with a useless error message.
    Folder name is not problematic, e.g. using MIDIio for folder and main class names.
    The only place that namespace (unique from class name) is referenced without specific [Nn]amespace label are:
    SettingsControl.xaml:?<UserControl x:Class="""
    Properties/Resources.Designer.cs:  global::System.Resources.ResourceManager
     temp = new global::System.Resources.ResourceManager("", typeof(Resources).Assembly);
    

    XAML user interface (ick) tutorials

  • Microsoft WPF XAML overview
  • WPF Controls Gallery
  • XAML Vs C# Code
  • Get Started (WPF)
  • Snoop WPF debugger   -   videos   -   documentation   -   videos:  3 tricks

    A simple WPF XAML app

    Get in the habit of checking .csproj file with a text editor

    IMO, changing via Visual Studio UI is harder than editing them in the .csproj file.
    I found and fixed several obvious inconsistencies e.g. in paths that way.

    Adding Melanchall.DryWetMidi Assemblies dependency

    VS volunteered Naudio but accepted Melanchall.DryWetMidi.dll.

    Vertical green bars in left margin:  recently saved changes (yellow before saving).

    Avoid upsetting VS by copying one object .cs to a .txt.

  • Edit the .txt into a new class, then rename to .cs.
  • maintained by blekenbleu