Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
vermeir_nico_introducing_net_6_getting_started_with_blazor_m.pdf
Скачиваний:
19
Добавлен:
26.06.2023
Размер:
11.64 Mб
Скачать

Chapter 3 Command Line Interface

"imports": [ "net48"

],

"assetTargetFallback": true, "warn": true, "frameworkReferences": {

"Microsoft.NETCore.App": { "privateAssets": "all"

}

},

"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\ sdk\\6.0.100\\RuntimeIdentifierGraph.json"

}

}

}

}

You can find this file in your project’s obj folder after dotnet restore should you want to take a look.

NuGet.config

Dotnet restore can take a nuget.config file into account. A nuget.config file can set different settings per project; it’s an XML file with one <configuration> top-level node.

Listing 3-6 shows an example of a nuget.config file.

Listing 3-6.  nuget.config example

<?xml version="1.0" encoding="utf-8"?> <configuration>

<config>

<!-- Set default install location for packages --> <add key="repositoryPath" value="%HOME%/Packages" />

</config>

43

Chapter 3 Command Line Interface

<packageRestore>

<add key="enabled" value="True" /> <add key="automatic" value="True" />

</packageRestore>

<!-- Specify package sources used for this project --> <packageSources>

<add key="NuGet official package source" value="https://api.nuget. org/v3/index.json" />

</packageSources>

<!-- Set Microsoft as trusted signer --> <trustedSigners>

<author name="microsoft">

<certificate fingerprint="3F9001EA83C560D712C24CF213C3D31 2CB3BFF51EE89435D3430BD06B5D0EECE" hashAlgorithm="SHA256" allowUntrustedRoot="false" />

<certificate fingerprint="AA12DA22A49BCE7D5C1AE64CC1F3D89 2F150DA76140F210ABD2CBFFCA2C18A27" hashAlgorithm="SHA256" allowUntrustedRoot="false" />

</author>

<repository name="nuget.org" serviceIndex="https://api.nuget.org/ v3/index.json">

<certificate fingerprint="0E5F38F57DC1BCC806D8494F4F90FBC EDD988B46760709CBEEC6F4219AA6157D" hashAlgorithm="SHA256" allowUntrustedRoot="false" />

<certificate fingerprint="5A2901D6ADA3D18260B9C6DFE2133C9 5D74B9EEF6AE0E5DC334C8454D1477DF4" hashAlgorithm="SHA256" allowUntrustedRoot="false" /> <owners>microsoft;aspnet;nuget</owners>

</repository>

</trustedSigners>

</configuration>

44

Chapter 3 Command Line Interface

The config file can contain a config section with:

•\ dependencyVersion

•\ globalPackagesFolder

•\ repositoryPath

•\ defaultPushSource

•\ proxy settings

•\ http_proxy

•\ http_proxy.user

•\ http_proxy.password

•\ no_proxy

•\ signatureValidationMode

The config file can also control binding redirects. Binding redirects trick .NET into believing an assembly is actually another one, for example, if one specific NuGet package needs an older version of another package, we can trick the compiler into thinking package v3.5 is actually package v2.0. NuGet can set those redirects in your projects automatically. We can control this behavior through the <bindingRedirects> section.

NuGet.config can contain instructions on automatic restore of packages during builds; this is enabled by default but can be disabled by setting automatic to false in the

<packageRestore> section.

If the nuget.config file is at solution level of a code base, we can control whether or not the packages themselves are included in source control by setting disableSourceControlIntegration in the <solution> section.

Probably the most used section in nuget.config is the <packageSources> section. This is used to add extra package sources where NuGet can look for packages, besides nuget.org. It can come in handy if you have an own private package feed, for example, Azure DevOps Artifact Feeds. Should one of those feeds need credentials, you can set those through <packageSourceCredentials> or through API keys via <apikeys>.

Besides explicitly defining package sources, we can also explicitly disable them through

<disabledPackageSource>.

45