简体   繁体   中英

How to fix target framework reference for windows application pack in visual studio

I have an asp web server target framework is .NET Framework 4.6.1,

<TargetFramework>net461</TargetFramework>

I would like to add this project to a Windows application package and generate an installer. After I build the package, an error message:

target'net461' it cannot be referenced by a project that targets '.NETCore,Version=v5.0'.

Severity Code Description Project File Line Suppression State Error Project '..\\Example\\Example.csproj' targets 'net461'. It cannot be referenced by a project that targets '.NETCore,Version=v5.0'. ExamplePackage C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\MSBuild\\Current\\Bin\\Microsoft.Common.CurrentVersion.targets 1653

I think it because windows application packaging has a default target framework but I have no idea how to change it. Could someone help me with this ?

I've found a solution:

You should specify on the project xml, under each reference, which target framework to use, like this:

<SetTargetFramework>TargetFramework=net461</SetTargetFramework>

Complete example for a given reference

    <ProjectReference Include="theProject.csproj">
      <Name>theProject</Name>
      <Project>{46e70050-559c-442f-b47d-99a3ad73afd3}</Project>
      <Private>True</Private>
      <DoNotHarvest>True</DoNotHarvest>
      <RefProjectOutputGroups>Binaries;Content;Satellites</RefProjectOutputGroups>
      <RefTargetDir>INSTALLFOLDER</RefTargetDir>
      <SetTargetFramework>TargetFramework=net461</SetTargetFramework>
    </ProjectReference>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM