NuGet程序包而不重建它

NuGet程序包而不重建它

本文介绍了如何打包.NET Standard NuGet程序包而不重建它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do you pack a .NET Standard NuGet package that has its Nuget specifications in the CSProj file without rebuilding it?

我需要一些自动化程序,它们之间需要运行与构建过程本身分离的构建步骤和打包步骤,不应视为与任何项目相关的构建事件。

I have some automation that needs to run between the build-step and the pack-step that is de-coupled from the build-process itself and shouldn't be a build-event tied to any projects.

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

When I try to use the nuget CLI, it fails with this:

错误NU5012:无法找到'bin\Debug\LibraryNuGetExample\ bin\Debug\。确保项目已构建。

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

This makes no sense as that's not the build output folder! The correct output folder is bin\Debug\** -- I don't understand why it's looking for this directory mapping that I didn't specify anywhere.

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

I tried using this, but it rebuilt, which I definitely don't want; just nuget pack:

MSBuild LibraryNuGetExample.csproj / t:pack

所以我要么需要知道如何操作,

So I either need to know how to,


  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>


推荐答案

您可以使用等价于

dotnet pack --no-build

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

which for MSBuild (since you're building for UAP) is

msbuild -t:Pack -p:NoBuild=true

这篇关于如何打包.NET Standard NuGet程序包而不重建它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 03:37