Search code examples
c#visual-studiovisual-studio-extensionsvsixtarget-framework

Interactive window support for multiple runtimes .NET Core in vsix template


In creating a template for VSIX we can allow the user to choose the .Net framework version This is how it is done:

<TargetFrameworkVersion>v$targetframeworkversion$</TargetFrameworkVersion>

Now, with the release of the new version of Visual Studio (16.8), This allows the user to select the .NET Core version as well. But this code does not seem to work in the .NET Core template project and shows different numbers instead of netcoreapp3.1 or net50-windows values. also .net core use <TargetFramework> instead of <TargetFrameworkVersion> so What is the correct parameter? I tested these:

1.result = 4.5

<TargetFrameworkVersion>$targetframeworkversion$</TargetFrameworkVersion>

2.result = $targetframework$

<TargetFramework>$targetframework$</TargetFramework>

3.result = 4.5

<TargetFramework>$targetframeworkversion$</TargetFramework>

Solution

  • I think you cannot create a such vsix project template for Net Core so far.

    I think you have created the project template project to realize your requirements.

    enter image description here

    And you should note that this project template uses the old sdk style format rather than the new-sdk format(Net Core). Also, what it passes in and out is always the framework of Net Framework.

    So no matter how you change its proj form on the basis of this template, it will always be net framework. You can see this interface, it is a custom template created by me, I will change it to use

    <Project Sdk="Microsoft.NET.Sdk">
    ....
    
    <TargetFramework>$targetframeworkversion$</TargetFramework>
    
    .....
    
    </Project>
    

    And I also unload the Project Template propject--> edit the xxx.csproj file ,change to use these:

     <Project Sdk="Microsoft.NET.Sdk">
        ....
        
        <TargetFramework>netcoreapp3.1</TargetFramework>
        
        .....
        
      </Project>
    

    Build the project template and put it into the C:\Users\xxx\Documents\Visual Studio 2019\Templates\ProjectTemplates.

    Restart VS and then use that tamplate, you can see this:

    enter image description here

    It always target with net frameowrk. And it proves that the modified framework is controlled by the internal parameters of the project template project itself, and we cannot change this internal parameter.

    In detailed, $targetframeworkversion$ is the parameter from the project template itself and since the project template is released by Microsoft with net framework, so the parameter is always net framework and other uncontrollable behavior can also lead to template project's corruption. So we cannot get the Net Core with that.

    Suggestion

    As a suggestion, you should contact with the Microsoft's Team on DC Forum or github to release a new project template project with the new sdk format(Net Core format).