C# .Net 如何将应用程序重定向到已安装的 .Net Framework(从控制台,无需 Visual Studio)

问题描述 投票:0回答:1

有人给我发送了一个解决方案,其中包含一些 C# 项目文件。我只使用 dotnet 的命令行界面,并且由于计算机内存不足而没有安装 Visual Studio。当尝试使用命令构建解决方案或仅构建单个项目文件时

dotnet build 

我收到以下错误:

MSBuild version 17.4.1+9a89d02ff for .NET
  Determining projects to restore...
  Nothing to do. None of the projects specified contain packages to restore.
C:\Program Files\dotnet\sdk\7.0.102\Microsoft.Common.CurrentVersion.targets(1229,5): error MSB3644: The reference assemblies for .NETFramework,Version=v4.7.2 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [D:\Informatik\NachhilfeInfoUni\C#MohammadTyp\ClientApp034 (2)\ClientApp034\Business.Model\Business.Model.csproj]

Build FAILED.

C:\Program Files\dotnet\sdk\7.0.102\Microsoft.Common.CurrentVersion.targets(1229,5): error MSB3644: The reference assemblies for .NETFramework,Version=v4.7.2 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [D:\Informatik\NachhilfeInfoUni\C#MohammadTyp\ClientApp034 (2)\ClientApp034\Business.Model\Business.Model.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.50

如果可能的话,我只想重新定位我的应用程序而不安装任何新内容。但我也很高兴能够下载正确的 .Net 框架,最好使用命令行(例如 dotnet Upgrade 之类的命令),下面是项目文件。我已经尝试过删除带有 TargetFrameworkVersion 的行。我也未能按照本教程找出我安装的.Net-Framework: 教程

如有任何帮助,我们将不胜感激

  <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{1F1F9B49-8ED7-4F08-9E82-7E0048581B7A}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>LernCard.Business.Model</RootNamespace>
    <AssemblyName>Business.Model</AssemblyName>
    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <Deterministic>true</Deterministic>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="BusinessObjects\Card.cs" />
    <Compile Include="BusinessObjects\CardCollection.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup />
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
c# .net nuget nuget-package
1个回答
0
投票

让我们看一下错误消息:

错误 MSB3644:找不到 .NETFramework、Version=v4.7.2 的参考程序集。要解决此问题,请安装此框架版本的开发人员包(SDK/目标包)或重新定位您的应用程序。您可以在 https://aka.ms/msbuild/developerpacks

下载 .NET Framework 开发人员包

所以,你有两个选择:

  1. 安装上述开发包
  2. 将您的应用程序重新定位为使用.NET Framework

第 1 点相当简单,但这意味着安装新东西。请记住,开发人员包不是完整的 Visual Studio 安装,而且它没有那么大。最重要的是,安装 .NET Framework runtime 是不够的(这是您链接的教程所处理的内容,因此无关紧要)。

但是,如果您真的想要避免安装它(这是明智的选择,因为 .NET Framework 又旧又臭),那么请继续第 2 点:重定向。在这种情况下,这实际上意味着“迁移”,因为它不一定是一个简单的过程。 Microsoft 有一个关于该主题的指南 最值得注意的是,您必须更改 .csproj 文件才能使用

SDK 样式项目格式

。 Microsoft 有一个工具可以自动化部分(甚至全部)工作,即 .NET 升级助手 然后,根据您的应用程序正在执行的操作,您可能需要考虑一些其他重大更改,但到那时您可能只需编译它并看看有什么问题就可以了。看看你的

.csproj

,它似乎是一个非常小的类库,带有一些 C# 文件,所以这不太可能是一个棘手的过程。

祝你好运!

© www.soinside.com 2019 - 2024. All rights reserved.