如何打包.NET标准NuGet程序包而不重建它?

时间:2018-11-30 23:54:09

标签: nuget nuget-package .net-standard nuget-spec

如何将具有Nuget规范的.NET Standard NuGet软件包打包到CSProj文件中,而无需重建它?

我有一些自动化需要在构建步骤和打包步骤之间运行,这些步骤与构建过程本身是分离的,并且不应该与任何项目捆绑在一起。

当我尝试使用nuget CLI时,此操作失败:

Error NU5012: Unable to find 'bin\Debug\LibraryNuGetExample\bin\Debug\'. Make sure the project has been built.

这没有意义,因为那不是构建输出文件夹!正确的输出文件夹是bin\Debug\** -我不明白为什么它要寻找我未在任何地方指定的目录映射。

我尝试使用它,但是它重建,我绝对不想要;只是nuget pack

MSBuild LibraryNuGetExample.csproj /t:pack

所以我要么需要知道如何做,

  1. 使用MSBuid仅打包而不使用某些当前未知的选项构建软件包
  2. 使用带有当前未知选项的NuGet CLI对其进行打包
  3. 我还没有考虑过的其他一些聪明的东西:)

LibraryNuGetExample.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>uap10.0;net45</TargetFrameworks>
    <PackageId>LibraryForNuGetExample</PackageId>
    <Authors>user name</Authors>
    <Company>ACME</Company>
    <Product>Library For NuGet Example</Product>
    <Description>A test package to test automation.</Description>
    <Copyright>ACME © 2018</Copyright>
    <PackageTags>DevOps Builds Testing</PackageTags>
    <PackageVersion>$(AssemblyVersion)</PackageVersion>
    <Platforms>x64;AnyCPU</Platforms>
    <NeutralLanguage>en-US</NeutralLanguage>
  </PropertyGroup>

  <PropertyGroup Condition="'$(TargetFramework)' == 'uap10.0'">
    <NugetTargetMoniker>UAP,Version=v10.0</NugetTargetMoniker>
    <TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
    <TargetPlatformVersion>10.0.15063.0</TargetPlatformVersion>
    <TargetPlatformMinVersion>10.0.15063.0</TargetPlatformMinVersion>
    <TargetFrameworkIdentifier>.NETCore</TargetFrameworkIdentifier>
    <TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
    <DefineConstants>$(DefineConstants);WINDOWS_UWP</DefineConstants>
    <LanguageTargets>$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets</LanguageTargets>
  </PropertyGroup>

   <ItemGroup>
    <None Include="LibraryForNuGetExample.targets" Pack="true" PackagePath="build\uap10.0" />
  </ItemGroup>

  <ItemGroup Condition=" '$(TargetFramework)' == 'uap10.0' ">
    <PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform " Version="5.2.2" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="Windows">
      <HintPath>C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.15063.0\Windows.winmd</HintPath>
      <IsWinMDFile>true</IsWinMDFile>
      <Private>true</Private>
    </Reference>
  </ItemGroup>

  <Target Name="CopyPackage" AfterTargets="Pack" Condition="'$(IsCrossTargetingBuild)' == 'true'">
    <Copy SourceFiles="$(OutputPath)$(PackageId).$(PackageVersion).nupkg" DestinationFolder="$(SolutionDir)Packages" />
  </Target>

</Project>

LibraryForNuGetExample.targets

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'UAP'">
    <ReferenceCopyLocalPaths>
        Include="$(MSBuildThisFileDirectory)bin\Release\uap10.0\LibraryNuGetExample.dll"
        Include="$(MSBuildThisFileDirectory)bin\Release\uap10.0\LibraryNuGetExample.pdb"
        Include="$(MSBuildThisFileDirectory)bin\Release\uap10.0\LibraryNuGetExample.pri"
    </ReferenceCopyLocalPaths>
  </ItemGroup>
  <ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'NET45'">
    <ReferenceCopyLocalPaths>
        Include="$(MSBuildThisFileDirectory)bin\Release\net45\LibraryNuGetExample.dll"
        Include="$(MSBuildThisFileDirectory)bin\Release\net45\LibraryNuGetExample.pdb"
        Include="$(MSBuildThisFileDirectory)bin\Release\net45\LibraryNuGetExample.pri"
    </ReferenceCopyLocalPaths>
  </ItemGroup>
</Project>

1 个答案:

答案 0 :(得分:1)

您可以使用等价于

dotnet pack --no-build

对于MSBuild(因为您正在为UAP进行构建),

msbuild -t:Pack -p:NoBuild=true