Visual Studio Project Item Template can't add reference assembly to .NET 5 projects

Anthony 6 Reputation points
2021-11-15T21:33:14.917+00:00

We have a item template that adds one of our DLLs as a reference to the target project. The item can be added to a C# or VB.NET project. I can add the item to a .NET Framework project without any issues. But when I add the item to a .NET 5 project, I get the error "The reference EntityModel could not be added to the project. This wizard will continue to run, but the resulting project may not build properly". I can add the DLL manually to the .NET 5 project without any problems.

  <TemplateContent>
    <References>
      <Reference>
        <Assembly>System.Data</Assembly>
      </Reference>
      <Reference>
        <Assembly>EntityModel</Assembly>
      </Reference>
    </References>
    <ProjectItem SubType="" TargetFileName="$fileinputname$.lcm" ReplaceParameters="false" CustomTool="MyModelGenerator">Model.lcm</ProjectItem>
  </TemplateContent>

As a test, I did try adding a <HintPath> with a hard coded path to the assembly but that didn't help either.

Any suggestions on what I need to change to avoid getting the error with .NET 5 projects?

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
2,438 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
6,997 questions
No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 29,236 Reputation points Microsoft MVP
    2021-11-16T00:39:07.867+00:00

    If you are trying to use .NET Core 5 say with .NET Framework 4.8 that is not possible. Consider if possible using net standard 2.0 rather than .NET Core 5 and note net standard over 2.0 will not compile with .NET Framework 4.8.

    So you have a decision to make as per above.