Pratiques Nuget C#
Votre projet étant amené a grandir et à se complexifier autant mettre en place des mesures qui supportent la mise à l'échelle.
Gestion unifiée des packages
Gestion des packages au niveau de la solution
- xUnit
- nSubstitute
- nSubstitute.Analyzers
- FluentAssertions
- FluentAssertions.Analyzers
<!--Add Test Packages in Test projects.-->
<ItemGroup Condition="$(IsTestProject) == 'true'">
<PackageReference Include="FluentAssertions" />
<!--Microsoft-->
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="MSTest.TestFramework" />
<!--XUnit-->
<PackageReference Include="xunit" />
<!--XUnit.Analyzer-->
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
Mapping de Source de Package
nuget.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- Define my package sources, nuget.org and contoso.com. -->
<!-- `clear` ensures no additional sources are inherited from another config file. -->
<packageSources>
<clear />
<!-- `key` can be any identifier for your source. -->
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="MyCustomFeedOrganisation" value="https://pkgs.dev.azure.com/custom/_packaging/feed/nuget/v3/index.json" />
</packageSources>
<!-- Microsoft.* packages will only come from nuget.org. -->
<!-- All other packages come from contoso.com by default. -->
<packageSourceMapping>
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
<packageSource key="MyCustomFeedOrganisation">
<package pattern="ORG.*" />
</packageSource>
</packageSourceMapping>
</configuration>
Centralisation des version de packages
- depuis le Directory.Build.props de la solution
- depuis le csproj du projet
Directory.packages
<Project><PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="MediatR" Version="12.3.0" />
<PackageVersion Include="Microsoft.Azure.AppConfiguration.Functions.Worker" Version="7.3.0" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker" Version="1.22.0" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.4" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.OpenApi" Version="1.5.1" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.3.2" />
<!--Application Insights-->
<PackageVersion Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.2.0" />
<!--Code Analyzers-->
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.Net.Compilers.Toolset" Version="4.10.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<!--Cosmos DB-->
<PackageVersion Include="Microsoft.Azure.Cosmos" Version="3.42.0" />
<!--Fluent-->
<PackageVersion Include="FluentAssertions" Version="6.12.0" />
<!--Microsoft-->
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="MSTest.TestFramework" Version="3.5.0" />
<!--XUnit-->
<PackageVersion Include="xunit" Version="2.9.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="ORG.Candice.Domain" Version="8.0.0" />
<PackageVersion Include="ORG.Candice.Infrastructure" Version="8.0.0" />
</ItemGroup>
</Project>
Commentaires
Enregistrer un commentaire