[英]How to add .Net Standard Nuget package into .Net 4.5 Framework Project?
[英]Why does dotnet build on a .NET Framework 4.5 project throw "This project references NuGet package(s) that are missing"?
使用终端命令do.net build
在 VS Code 中构建的示例NotepadAndCalculatorTest项目抛出以下错误:
C:\Program Files\dotnet\sdk\5.0.401\Microsoft.Common.CurrentVersion.targets(820,5): error : The BaseOutputPath/OutputPath property is not set for project 'NotepadCalculatorTest.csproj'. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration='Debug' Platform='AnyCPU'. You may be seeing this message because you are trying to build a project without a solution file,
and have specified a non-default Configuration or Platform that doesn't exist for this project. [C:\Users\<username>\VSCode Projects\WinAppDriverTryout\Test\Samples\C#\NotepadAndCalculatorTest\NotepadCalculatorTest.csproj]
或者:
NotepadCalculatorTest.csproj(109,5): error : This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is packages\MSTest.TestAdapter.1.2.0\build\net45\MSTest.TestAdapter.props.
有人可以指出一种可能的方法来消除错误吗?
do.net build
作为命令的一部分执行隐式恢复。
这使用不支持packages.config
中的项目引用的do.net restore
& 正是这个项目正在使用的。
do.net restore
仅支持.csproj
package 引用。
这就是为什么这个项目在 Visual Studio 中构建得非常好,但是do.net build
会抛出错误。
您可以通过在 Visual Stduio 中右键单击该文件并单击迁移来将packages.config
迁移到do.net cli
引用,但是这仍然不能解决您的问题,因为只有当项目是使用do.net new
命令。
我假设这个项目是在 Visual Studio 中创建的,因为它有一个 Visual Studio 解决方案文件 - .sln
- 因此通常具有不同结构的.csproj
格式。
这通常会破坏一些 CLI 命令,即使您在这种情况下迁移了引用也是如此。
您有 2 个解决方法。
1.使用nuget restore
最简单的选择是从此处下载 NuGet CLI 可执行文件,它取自下载页面。
如果您不在 Windows,请使用Microsoft 提供的本指南。
将它添加到您的 PATH 或将其放在项目的根文件夹中。
运行nuget restore
,它与packages.config
兼容(如果您在 PowerShell 中,请运行.\nuget restore
以信任该命令,因为 PowerShell 默认情况下不会从当前位置加载命令以确保安全)。
你应该得到类似这样的 output:
PS C:\Users\StackOverflow\NotepadAndCalculatorTest> .\nuget restore
MSBuild auto-detection: using msbuild version '16.9.0.16703' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\bin'.
Restoring NuGet package Microsoft.WinAppDriver.Appium.WebDriver.1.0.1-Preview.
Restoring NuGet package Selenium.Support.3.8.0.
Restoring NuGet package Selenium.WebDriver.3.8.0.
Restoring NuGet package Castle.Core.4.2.1.
Restoring NuGet package MSTest.TestFramework.1.2.0.
Restoring NuGet package Newtonsoft.Json.10.0.3.
Restoring NuGet package MSTest.TestAdapter.1.2.0.
Adding package 'MSTest.TestFramework.1.2.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Adding package 'Selenium.Support.3.8.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Adding package 'Castle.Core.4.2.1' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Adding package 'Microsoft.WinAppDriver.Appium.WebDriver.1.0.1-Preview' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Adding package 'Selenium.WebDriver.3.8.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Adding package 'Newtonsoft.Json.10.0.3' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Adding package 'MSTest.TestAdapter.1.2.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Added package 'Microsoft.WinAppDriver.Appium.WebDriver.1.0.1-Preview' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Added package 'Selenium.Support.3.8.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Added package 'Selenium.WebDriver.3.8.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Added package 'Castle.Core.4.2.1' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Added package 'Newtonsoft.Json.10.0.3' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Added package 'MSTest.TestAdapter.1.2.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
Added package 'MSTest.TestFramework.1.2.0' to folder 'C:\Users\StackOverflow\NotepadAndCalculatorTest\packages'
NuGet Config files used:
C:\Users\StackOverflow\AppData\Roaming\NuGet\NuGet.Config
C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.FallbackLocation.config
C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config
Feeds used:
C:\Users\StackOverflow\.nuget\packages\
https://api.nuget.org/v3/index.json
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
Installed:
7 package(s) to packages.config projects
然后运行do.net build
。
它不会尝试运行do.net restore
因为包已经被 NuGet 恢复所以你不会得到任何错误:
PS C:\Users\StackOverflow\NotepadAndCalculatorTest> dotnet build
Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
Nothing to do. None of the projects specified contain packages to restore.
NotepadCalculatorTest -> C:\Users\StackOverflow\NotepadAndCalculatorTest\bin\Debug\NotepadCalculatorTest.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:01.08
2.移植项目
第二个解决方法是使用do.net new
创建一个新项目并移植代码,以便您的.csproj
文件与do.net restore
以及随后的do.net build
工作。
我会推荐选项 1,除非您不想通过 NuGet 恢复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.