不应仅在Visual Studio 2019上构建的交叉定位(外部)中,不应使用非crosstargeting getTargetFrameWorks目标

发布于 2025-02-06 23:23:58 字数 2371 浏览 0 评论 0原文

我有一个具有一个具有控制台项目的解决方案,该项目指的是一个类库项目。它在Visual Studio 2017中的预期工作。但是,当我尝试在Visual Studio 2019中构建解决方案时,它在控制台应用程序项目中给出了以下错误。

不应在 交叉定位(外部)构建

类库CSPROJ文件。

  <PropertyGroup>
    <TargetFrameworks>net472</TargetFrameworks>
  </PropertyGroup>
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{E05F3549-01FC-4012-A2CA-5BF009608E80}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>FxRateCalculationLib</RootNamespace>
    <AssemblyName>FxRateCalculationLib</AssemblyName>
    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>

控制台应用程序CSPROJ文件。

  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{34A8C575-F374-4C50-8ADC-EC74A6423055}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <RootNamespace>ConsoleApp1</RootNamespace>
    <AssemblyName>ConsoleApp1</AssemblyName>
    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <Deterministic>true</Deterministic>
    <TargetFrameworkProfile />

我试图从那时变化

<PropertyGroup>
    <TargetFrameworks>net472</TargetFrameworks>
  </PropertyGroup>

<PropertyGroup>
    <TargetFramework>net472</TargetFramework>
  </PropertyGroup>

那时,它成功地构建了。但是当我运行时,它会开始给出运行时错误。

因此,我有一个问题,为什么它在VS 2017中起作用,而在2019年不起作用。以及如何以最小和适当的更改来解决此问题。

编辑:最初,我认为这是一个旧的旧版项目,因此我使用Visual Studio 2019添加了一个新的控制台应用程序项目。但是上面的问题中提到了相同的汇编错误。

edit2 :完整的错误消息

严重性代码描述项目文件行抑制状态 错误内部msbuild错误:非crostargeting getTargetFrameworks 目标不应用于交叉靶向(外部) 构建consoleapp1

I have a Solution that has a console project which is referring to one class library project. It's working as expected in Visual Studio 2017. But When I try to build the solution in Visual Studio 2019 it gives the below error in the console app project.

Non-CrossTargeting GetTargetFrameworks target should not be used in
cross targeting (outer) build

Class library csproj file.

  <PropertyGroup>
    <TargetFrameworks>net472</TargetFrameworks>
  </PropertyGroup>
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{E05F3549-01FC-4012-A2CA-5BF009608E80}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>FxRateCalculationLib</RootNamespace>
    <AssemblyName>FxRateCalculationLib</AssemblyName>
    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>

Console app csproj file.

  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{34A8C575-F374-4C50-8ADC-EC74A6423055}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <RootNamespace>ConsoleApp1</RootNamespace>
    <AssemblyName>ConsoleApp1</AssemblyName>
    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <Deterministic>true</Deterministic>
    <TargetFrameworkProfile />

I tried to change changing from

<PropertyGroup>
    <TargetFrameworks>net472</TargetFrameworks>
  </PropertyGroup>

to

<PropertyGroup>
    <TargetFramework>net472</TargetFramework>
  </PropertyGroup>

then it builds successfully. but When I run It starts giving runtime errors.

So I have a question why is it working in VS 2017, but not in 2019. and how to fix this issue with minimum and proper changes.

Edit: initially I thought that it was an old legacy project, so I add a new console application project using visual studio 2019. But same compilation error is mentioned above in the question.

Edit2: Complete error message

Severity Code Description Project File Line Suppression State
Error Internal MSBuild error: Non-CrossTargeting GetTargetFrameworks
target should not be used in cross targeting (outer)
build ConsoleApp1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文