如何在不重建的情况下打包 .NET Standard NuGet 包?
How do you pack a .NET Standard NuGet package without rebuilding it?
如何打包在 CSProj 文件中具有 Nuget 规范的 .NET Standard NuGet 包而不重新构建它?
我有一些自动化需要 运行 在构建步骤和打包步骤之间,它与构建过程本身是分离的,不应该是与任何相关联的构建事件项目。
当我尝试使用 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
所以我要么需要知道怎么做,
- 使用 MSBuid 仅打包而不构建包含一些当前未知选项的包
- 使用当前未知选项的 NuGet CLI 来打包它
- 我还没有考虑其他一些聪明的事情:)
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\UnionMetadata.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 构建)是
msbuild -t:Pack -p:NoBuild=true
如何打包在 CSProj 文件中具有 Nuget 规范的 .NET Standard NuGet 包而不重新构建它?
我有一些自动化需要 运行 在构建步骤和打包步骤之间,它与构建过程本身是分离的,不应该是与任何相关联的构建事件项目。
当我尝试使用 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
所以我要么需要知道怎么做,
- 使用 MSBuid 仅打包而不构建包含一些当前未知选项的包
- 使用当前未知选项的 NuGet CLI 来打包它
- 我还没有考虑其他一些聪明的事情:)
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\UnionMetadata.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 构建)是
msbuild -t:Pack -p:NoBuild=true