visual-studio - MSB3644 找不到框架的引用程序集

标签 visual-studio msbuild visual-studio-2017 assemblies .net-standard

我收到以下 MSB3644 复杂错误:

The reference assemblies for framework ".NETFramework,Version=v4.0" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.

根据我读到的内容here ,这是由于我的机器上的程序集存储在“程序文件”而不是“程序文件(x86)”中。 MSBuild 上的 FrameworkPathOverride 属性可以修复此问题。

我尝试将此属性 (FrameworkPathOverride) 添加到 csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <Import Project="..\..\tools\common.props" />
  <PropertyGroup>
    <TargetFrameworks>net40;net45;netstandard1.2</TargetFrameworks>
    <GeneratePackageOnBuild>False</GeneratePackageOnBuild>
    <FrameworkPathOverride>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0</FrameworkPathOverride>
  </PropertyGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'net40' ">
    <Reference Include="System.Configuration" />
  </ItemGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
    <Reference Include="System.Configuration" />
  </ItemGroup>
  <PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.2' ">
    <DefineConstants>$(DefineConstants);NETSTANDARD</DefineConstants>
  </PropertyGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.2' ">
  </ItemGroup>
</Project>

该错误随后消失,但无法解析我的所有类型和命名空间,并且我还收到此构建警告:

MSB3270 There was a mismatch between the processor architecture of the project being built "AMD64" and the processor architecture of the reference "C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.

将项目的目标框架设置为 x86 后,警告消失,但仍然无法解析类型或命名空间。

我已经安装了所有必要的框架:

enter image description here

我在 Windows 10 上使用 Visual Studio 2017。

最佳答案

遇到同样的错误。框架版本已正确安装在我的计算机上(运行该特定版本框架的安装程序没有执行任何操作 - 它告诉我它已经安装)。 但该框架并未“作为 Visual Studio 的一部分”安装。

是什么为我解决了这个问题: 运行VS安装程序(如果丢失,请重新下载from here),在Visual Studio上单击“修改”,转到“单个组件”选项卡,然后检查.NET类别下缺少的内容。

我没有在我的 csproj 上设置任何 FrameworkPathOverride。

关于visual-studio - MSB3644 找不到框架的引用程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45303001/

相关文章:

visual-studio - 得到 : "There is no source code available for the current location." 后如何让 Visual Studio 询问源路径

msbuild - 如何在 msbuild 目标中获取进程 ID

c++ - Visual C++完美转发编译报错

git - Azure DevOps 中新创建的 git 分支未显示在 Visual Studio 2017 中

asp.net - <_CustomFiles> 元素在 .pubxml 中无法识别

c++ - Visual Studio 2015 上的日志

xml - 自动生成XSD方案错误: global element 'configuration' has already been declared

jenkins - 在命令行中构建 UWP 应用程序(使用 MSBUILD)

c# - 依赖项未复制到 bin 文件夹

visual-studio - 将LLVM Clang 4.x.x/5.x.x/6.x.x集成到Visual Studio 2017中