我不能运行单元测试。

我有下一个错误:

你的项目没有引用“.NETFramework,Version=v4.6.2” 框架。在。net framework,Version=v4.6.2中添加一个引用 “TargetFrameworks”属性,然后重新运行NuGet 恢复。

在app.config:

<startup>
  <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
</startup>

在项目>属性>应用>目标框架(。NET Framework 4.6.2)

我该怎么解决呢?


当前回答

我已经删除了obj文件夹,并在属性窗口中选择所需的目标框架后重新运行构建,它为我工作。

其他回答

重命名项目为我解决了这个错误。问题发生在我创建。net Core项目之后,然后我删除了它,并创建了一个同名的。net Standard项目。Obj文件夹根本不存在。删除bin文件夹,包,清洁和重建解决方案和获得最新的覆盖没有帮助。

我没有尝试过,但是这个线程提出的解决方案是包括在csproj标签中:

<ResolveNuGetPackages>false</ResolveNuGetPackages>

我正在使用一个非常老的。net项目,它一直工作得很好,直到它突然停止。升级Visual Studio固定为我你。

我已经删除了obj文件夹,并在属性窗口中选择所需的目标框架后重新运行构建,它为我工作。

我也遇到过类似的问题,但使用的是v4.7.2。也就是说,我一直得到这样的构建日志消息:

错误:你的项目没有引用“. net framework,Version=v4.7.2”框架。在项目文件的“TargetFrameworks”属性中添加对“. net framework,Version=v4.7.2”的引用,然后重新运行NuGet还原。

尽管看起来很相似,但上面建议的步骤对我都不起作用。每次构建之后,我都会看到这条消息。似乎什么也帮不上忙。

In fact, the problem was related to that, due to migration, I had to put two projects in one folder of code. One of them was targeted at .Net Core, another at .Net Framework, both referenced same .Net Standard libraries. Apparently, they share the same obj folder where Core projects put project.assets.json file. Actually, exactly this file interferres with the Framework project preventing its normal build. Seems even if you performed Migrate from packages.config to PackageReference... which was recommended as one of possible solution.

你可以尝试通过将下面的代码片段放入你的框架项目文件来修复这个问题:

<Project>
  ...
  <PropertyGroup>
    <BaseOutputPath>$(MSBuildProjectDirectory)/out/$(MSBuildProjectName)/bin</BaseOutputPath>
    <BaseIntermediateOutputPath>$(MSBuildProjectDirectory)/out/$(MSBuildProjectName)/obj</BaseIntermediateOutputPath>
  </PropertyGroup>
  ...
</Project>

它立刻对我起了作用,直到后来我仔细地读到为什么我们需要它,为什么它起作用。我意外地在《确保。net框架项目仍然构建》的第2部分将一个样本WPF应用程序迁移到。net Core 3中发现了它。BaseOutputPath和BaseIntermediateOutputPath msbuild变量可以在那里找到,不确定它们是否在任何地方都有良好的文档。

请做下一步

清洁解决方案 清洁文件夹“包” 删除文件夹“bin” 删除文件夹"obj"