C# 項目的依賴設置
不同版本的C#, 其項目依賴設置有不同的寫法.
下面內容摘自 https://fossa.com/blog/managing-dependencies-net-csproj-packagesconfig/
.NET Framework pre-NuGet (before 2010)
Prior to the advent of .NET Core, a project was represented by a .csproj file, and all the dependencies were represented in the same file. If you wanted to reference a third-party library, you had to find it on the web, download it, place it in a folder, and add a project reference to it in the .csproj file.
.NET Framework with NuGet (2010 - 2016)
A project was represented by a .csproj file but the dependencies (including NuGet package references) were kept separately in a packages.config file. Here, you could get your third-party libraries from the NuGet central public collection and transfer your project to another machine without copying the libraries — simply copy the packages.config file and do a package restore.

Initial .NET Core (2015 - 2017)
The first .NET Core projects created in Visual Studio 2015 were represented by an .xproj file (similar to .csproj) and the dependencies (NuGet package references) stored in a project.json file. This approach is now deprecated.
.NET Core is born (2017 - today)
Since Visual Studio 2017, a project has been represented by a **.csproj ** file with dependencies (NuGet package references) listed in the **PackageReference ** section of this file. For some types of projects, dependencies are still kept in that separate packages.config file.

Disable nuget restore when build
nuget restore 會自動解析項目配置文件的依賴項, 并在需要的時候從nuget倉庫下載依賴程序文件, 這個restore會在build/publish/run/test/new/pack時自動觸發的, 但這會拉慢編譯速度. 可以在項目根目錄增加一個 Nuget.config 文件, 在文件中禁用自動 nuget restore.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<!-- Opts out of both Automatic Package Restore and MSBuild-Integrated Package Restore -->
<add key="enabled" value="False" />
<!-- Opts out of Automatic Package Restore in Visual Studio -->
<add key="automatic" value="False" />
</packageRestore>
</configuration>
手動執行restore命令為:
# restore 當前目錄中的項目
dotnet restore
#restore 指定項目
dotnet restore ./projects/app1/app1.csproj

浙公網安備 33010602011771號