为什么基于 .NET Framework 4.5 项目构建的 dotnet 会抛出 "This project references NuGet package(s) that are missing"?
Why does dotnet build on a .NET Framework 4.5 project throw "This project references NuGet package(s) that are missing"?
使用终端命令 dotnet build
在 VS Code 中构建的示例 NotepadAndCalculatorTest 项目抛出以下错误:
C:\Program Files\dotnet\sdk.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.
有人能告诉我消除错误的可能方法吗?
dotnet build
carries out an implicit restore 作为命令的一部分。
这使用 dotnet restore
不支持 packages.config
中的项目引用 & 这正是该项目正在使用的内容。
dotnet restore
仅支持 .csproj
包引用。
这就是为什么这个项目在 Visual Studio 中构建得非常好,但是 dotnet build
会抛出错误。
您可以可以通过在 Visual Stduio 中右键单击文件并单击迁移来将 packages.config
迁移到包引用,但是这仍然不能解决您的问题,因为dotnet cli
只有在项目是使用 dotnet new
命令创建的情况下才能与 .NET Framework 一起正常工作。
我假设这个项目是在 Visual Studio 中创建的,因为它有一个 Visual Studio 解决方案文件 - .sln
- 因此通常具有不同结构的 .csproj
格式。
这通常会破坏一些 CLI 命令,即使您在这种情况下迁移引用也是如此。
您有 2 个解决方法。
1.使用 nuget restore
最简单的选择是从 here, taken from the downloads page 下载 NuGet CLI 可执行文件。
如果您不在 Windows,请使用 this guide by Microsoft。
将其添加到您的 PATH 或将其放在项目的根文件夹中。
运行 nuget restore
,与 packages.config
兼容(运行 .\nuget restore
如果您在 PowerShell 中信任该命令,因为 PowerShell 不为了安全起见,默认情况下不会从当前位置加载命令。
你应该得到类似这样的输出:
PS C:\Users\Whosebug\NotepadAndCalculatorTest> .\nuget restore
MSBuild auto-detection: using msbuild version '16.9.0.16703' from 'C:\Program Files (x86)\Microsoft Visual Studio19\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\Whosebug\NotepadAndCalculatorTest\packages'
Adding package 'Selenium.Support.3.8.0' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Adding package 'Castle.Core.4.2.1' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Adding package 'Microsoft.WinAppDriver.Appium.WebDriver.1.0.1-Preview' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Adding package 'Selenium.WebDriver.3.8.0' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Adding package 'Newtonsoft.Json.10.0.3' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Adding package 'MSTest.TestAdapter.1.2.0' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Added package 'Microsoft.WinAppDriver.Appium.WebDriver.1.0.1-Preview' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Added package 'Selenium.Support.3.8.0' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Added package 'Selenium.WebDriver.3.8.0' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Added package 'Castle.Core.4.2.1' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Added package 'Newtonsoft.Json.10.0.3' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Added package 'MSTest.TestAdapter.1.2.0' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Added package 'MSTest.TestFramework.1.2.0' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
NuGet Config files used:
C:\Users\Whosebug\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\Whosebug\.nuget\packages\
https://api.nuget.org/v3/index.json
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
Installed:
7 package(s) to packages.config projects
然后 运行 dotnet build
.
它不会尝试 运行 dotnet restore
因为包已经被 NuGet 恢复所以你不会得到任何错误:
PS C:\Users\Whosebug\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\Whosebug\NotepadAndCalculatorTest\bin\Debug\NotepadCalculatorTest.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:01.08
2。移植项目
第二个解决方法是使用 dotnet new
创建一个新项目并将代码移植过来,以便您的 .csproj
文件与 dotnet restore
以及随后的 dotnet build
一起工作。
除非您不想通过 NuGet 恢复,否则我会推荐选项 1。
使用终端命令 dotnet build
在 VS Code 中构建的示例 NotepadAndCalculatorTest 项目抛出以下错误:
C:\Program Files\dotnet\sdk.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.
有人能告诉我消除错误的可能方法吗?
dotnet build
carries out an implicit restore 作为命令的一部分。
这使用 dotnet restore
不支持 packages.config
中的项目引用 & 这正是该项目正在使用的内容。
dotnet restore
仅支持 .csproj
包引用。
这就是为什么这个项目在 Visual Studio 中构建得非常好,但是 dotnet build
会抛出错误。
您可以可以通过在 Visual Stduio 中右键单击文件并单击迁移来将 packages.config
迁移到包引用,但是这仍然不能解决您的问题,因为dotnet cli
只有在项目是使用 dotnet new
命令创建的情况下才能与 .NET Framework 一起正常工作。
我假设这个项目是在 Visual Studio 中创建的,因为它有一个 Visual Studio 解决方案文件 - .sln
- 因此通常具有不同结构的 .csproj
格式。
这通常会破坏一些 CLI 命令,即使您在这种情况下迁移引用也是如此。
您有 2 个解决方法。
1.使用 nuget restore
最简单的选择是从 here, taken from the downloads page 下载 NuGet CLI 可执行文件。
如果您不在 Windows,请使用 this guide by Microsoft。
将其添加到您的 PATH 或将其放在项目的根文件夹中。
运行 nuget restore
,与 packages.config
兼容(运行 .\nuget restore
如果您在 PowerShell 中信任该命令,因为 PowerShell 不为了安全起见,默认情况下不会从当前位置加载命令。
你应该得到类似这样的输出:
PS C:\Users\Whosebug\NotepadAndCalculatorTest> .\nuget restore
MSBuild auto-detection: using msbuild version '16.9.0.16703' from 'C:\Program Files (x86)\Microsoft Visual Studio19\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\Whosebug\NotepadAndCalculatorTest\packages'
Adding package 'Selenium.Support.3.8.0' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Adding package 'Castle.Core.4.2.1' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Adding package 'Microsoft.WinAppDriver.Appium.WebDriver.1.0.1-Preview' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Adding package 'Selenium.WebDriver.3.8.0' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Adding package 'Newtonsoft.Json.10.0.3' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Adding package 'MSTest.TestAdapter.1.2.0' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Added package 'Microsoft.WinAppDriver.Appium.WebDriver.1.0.1-Preview' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Added package 'Selenium.Support.3.8.0' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Added package 'Selenium.WebDriver.3.8.0' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Added package 'Castle.Core.4.2.1' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Added package 'Newtonsoft.Json.10.0.3' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Added package 'MSTest.TestAdapter.1.2.0' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
Added package 'MSTest.TestFramework.1.2.0' to folder 'C:\Users\Whosebug\NotepadAndCalculatorTest\packages'
NuGet Config files used:
C:\Users\Whosebug\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\Whosebug\.nuget\packages\
https://api.nuget.org/v3/index.json
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
Installed:
7 package(s) to packages.config projects
然后 运行 dotnet build
.
它不会尝试 运行 dotnet restore
因为包已经被 NuGet 恢复所以你不会得到任何错误:
PS C:\Users\Whosebug\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\Whosebug\NotepadAndCalculatorTest\bin\Debug\NotepadCalculatorTest.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:01.08
2。移植项目
第二个解决方法是使用 dotnet new
创建一个新项目并将代码移植过来,以便您的 .csproj
文件与 dotnet restore
以及随后的 dotnet build
一起工作。
除非您不想通过 NuGet 恢复,否则我会推荐选项 1。