What nuget packages to use targeting .Net 5 or .Net 6?

Ken Blaker 1 Reputation point
2021-07-28T21:46:14.413+00:00

I am building a new MSTest project using VS 2019. I can also use VS 2022 preview with .Net 6 if that would be better.

An earlier version of a test project was built using VS 2017 and targeted .Net Framework 4.62.

Using the newer VS I can no longer target .Net Framework 4.62. The default is .Net 5. (and for VS 2022 the default is .Net 6).

Some of the nuget packages I've depended on are either not available form .Net 5 or 6 or have changed.

1 - I am having trouble getting to the Clipboard. I cannot find a nuget for System.Windows.Forms, or for PresentationCore.dll within namespace System.Windows (The MS website documents both of those namespaces - but does not state which package to install to get them).

2 - I need to share some of the test info with TFS work items. What package includes TeamFoundation WorkItemTracking?

3 - Also for TFS I need Microsoft.VisualStudio.Services.WebApi.VssConnection - but cannot find it.

4 - Also for TFS I am looking a class like System.Web.Util.WorkItem.

I need help!! I also strongly recommend that MS start adding notes regarding which nuget packages to use to access the namespaces documented in the MS website. That would save developers millions of hours, no doubt. Since the classes I am looking for are documented by MS, I am avoiding third party packages.

Developer technologies C#
{count} votes

5 answers

Sort by: Most helpful
  1. Ken Blaker 1 Reputation point
    2021-07-29T02:41:26.643+00:00

    Hi Lextm.

    I was not trying to open the old project in VS 2019 or VS 2022. I was trying to start a new test project and do the same things as the old project did.

    When I choose to start a new project in VS 2019 or VS 2022, old .Net Framework versions are not listed as available targets - just .Net 5 (on 2019) or .Net 6 (on 2022), and some versions of .Net Core.

    So, as an example, when I went to try to use the clipboard, I could not reference the Clipboard class. Initially I assumed I needed to add a reference (the references group in the solution explorer is now named Dependencies). But I looked all over for a package that i could add that included the clipboard class and could not find it. (I found documentation listing it in System.Windows or System.Windows.Forms - but cannot find a package that includes either of those namespaces.

    That is why I suggested that the Microsoft documentation of this class (and the other classes I mentioned) should include package names that we developers can look up and include.

    Hope this is clear.

    From your question I am thinking that I could probably build the project in VS 2017, targeting a recent .Net Framework version - and then open in in VS 2019 or 2022.
    That might work but I think it is a lousy solution for going forward.

    Ken

    0 comments No comments

  2. Timon Yang-MSFT 9,606 Reputation points
    2021-07-29T08:53:10.95+00:00

    Please try to modify the csproj file of this project.

    For System.Windows(WPF):

       <Project Sdk="Microsoft.NET.Sdk">  
          <PropertyGroup>  
            <OutputType>Exe</OutputType>  
            <TargetFramework>net5.0-windows</TargetFramework>  
            <UseWPF>true</UseWPF>  
          </PropertyGroup>  
        </Project>  
    

    For System.Windows.Forms(WinForm):

    <Project Sdk="Microsoft.NET.Sdk">  
      <PropertyGroup>  
        <OutputType>Exe</OutputType>  
        <TargetFramework>net5.0-windows</TargetFramework>  
        <UseWindowsForms>true</UseWindowsForms>  
      </PropertyGroup>  
    </Project>  
    

    Then we can use it.

    119013-capture.png


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  3. Ken Blaker 1 Reputation point
    2021-07-29T17:23:44.703+00:00

    Thanks! That worked.

    FYI - I first added the element " <UseWindowsForms>true</UseWindowsForms>" which did not work by itself.

    Then I changed the TargetFramework from "net5.0" tp "net5.0-windows" - and then it worked. This was enlightening for me.

    I am still having trouble with TFS WorkItems. The using i have is:
    using WorkItem = System.Web.Util.WorkItem;

    The Util references is not resolving. Here's a screen snip:
    119144-image.png

    Please let me know any thoughts about how to solve this.

    FYI - (I mention this hoping the feedback gets back to the right product manager(s)... ) - For a mid-level developer like me, this seems much harder, and much less documented, than it needs to be. This seems to me like an area where MS could do a much better job, and save developers a huge amount of time - especially related to MS tools like this windows forms reference and interfacing with TFS (or now Azure DevOps).

    And FYI - here is my full csproj (I edit out some proprietary references - but thought the TFS client package reference might help you see where i am):

    <Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
    <IsPackable>false</IsPackable>
    </PropertyGroup>

    <ItemGroup>
    <PackageReference Include="DocumentFormat.OpenXml" Version="2.13.0" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
    <PackageReference Include="Microsoft.TeamFoundationServer.Client" Version="16.170.0" />
    <PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
    <PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
    <PackageReference Include="coverlet.collector" Version="3.1.0">
    <PrivateAssets>all</PrivateAssets>
    <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
    <PackageReference Include="RestSharp" Version="106.12.0" />
    </ItemGroup>
    </Project>

    0 comments No comments

  4. Karen Payne MVP 35,586 Reputation points Volunteer Moderator
    2021-07-29T17:31:45.857+00:00

    Hello,

    Consider creating a base project, set it up for your needs then do an export to a package. Once exported the exported project is placed with standard templates and you can then select your new package.

    Since I do web and windows many of my packages have -windows which I can easily remove.

    And anyone who wants to use pre-defined project templates I created they are in this GitHub repository.

    Listing of project template in the repository

    119084-figure1.png

    Showing several templates in Visual Studio

    119129-figure2.png

    0 comments No comments

  5. Ken Blaker 1 Reputation point
    2021-07-29T17:48:23.123+00:00

    Thanks KarenPayne - I didn't know that could be done. Cool! I've been using VS and C# for about 4 years, and have a real love/hate relationship with VS - especially with regard to packages and references. I live with a copy of C# In A Nutshell nearby. I wish there was a similar reference for VS. There seems to be a huge amount of tribal knowledge that people like me (not working in a big organization) simply don't have easy access to.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.