.NET Core 项目根据不同条件编译引入类库、Nuget

内容纲要

背景:
调试测试 Debug 时需要使用 NSwag.AspNetCore ,提供 swagger 服务,但是正式发布部署,不需要用到。 NSwag.AspNetCore 的库文件达到6MB。
可以在项目文件中使用如下条件 Condition="'$(Configuration)'=='DEBUG'"
示例:

    <PackageReference Condition="'$(Configuration)'=='DEBUG'" Include="NSwag.AspNetCore" Version="13.2.0" />

大佬的示例

<Project>
  <PropertyGroup>
        <VersionMajor>1</VersionMajor>
        <VersionMinor>8</VersionMinor>
        <VersionPatch>2</VersionPatch>
        <VersionRevision>0</VersionRevision>
        <VersionPrefix Condition="'$(VersionRevision)'=='0'">$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
    <VersionPrefix Condition="'$(VersionRevision)'!='0'">$(VersionMajor).$(VersionMinor).$(VersionPatch).$(VersionRevision)</VersionPrefix>
        <VersionSuffix Condition="'$(Configuration)'=='DEBUG'">preview-$([System.DateTime]::Now.ToString("yyyyMMdd-HHmmss"))</VersionSuffix>
    <InformationalVersion>$(PackageVersion)</InformationalVersion>
    </PropertyGroup>

  <PropertyGroup>
    <LangVersion>latest</LangVersion>

    <RepositoryType>git</RepositoryType>
    <RepositoryUrl>https://github.com/WeihanLi/WeihanLi.Npoi</RepositoryUrl>
    <!-- Optional: Publish the repository URL in the built .nupkg (in the NuSpec <Repository> element) -->
    <PublishRepositoryUrl>true</PublishRepositoryUrl>
    <!-- Optional: Build symbol package (.snupkg) to distribute the PDB containing Source Link -->
    <IncludeSymbols>true</IncludeSymbols>
    <SymbolPackageFormat>snupkg</SymbolPackageFormat>

    <Authors>WeihanLi</Authors>
    <Copyright>Copyright 2017-2019 (c) WeihanLi</Copyright>
    <NoWarn>$(NoWarn);NU5048;</NoWarn>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Condition="'$(OS)' == 'Windows_NT'" Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
    <PackageReference Condition="'$(OS)' != 'Windows_NT'" Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All"/>
    <PackageReference Include="JetBrains.Annotations" Version="2019.1.3" PrivateAssets="All" />
  </ItemGroup>
</Project>

地址:https://github.com/WeihanLi/WeihanLi.Npoi/blob/dev/Directory.Build.props

点赞

发表评论

电子邮件地址不会被公开。 必填项已用*标注