简体   繁体   English

使用Visual Studio Pack将构建目录包含在nuget包中

[英]Include build directory in nuget package using visual studio pack

I'm attempting to create a nupkg with Visual Studio using the built in nuget package building and include the build directory from my project in the nupkg. 我正在尝试使用内置的nuget软件包构建用Visual Studio创建nupkg,并将项目中的build目录包括在nupkg中。 It seems like it should be a fairly simple task but I can't get it to work. 看来这应该是一个相当简单的任务,但我无法使其正常工作。 From my googling adding either of these to my csproj file should work, but both create an empty 'build' directory in the nupkg: 从我的谷歌搜索到我的csproj文件添加应该工作,但两者都在nupkg中创建一个空的'build'目录:

 <ItemGroup>
    <None Include="build\**">
      <Pack>true</Pack>
      <PackagePath>build\</PackagePath>
      <IncludeInPackage>true</IncludeInPackage>
    </None>
  </ItemGroup>

Using nuget pack to create the package with the following in my nuspec does work: 在我的nuspec中使用nuget pack创建具有以下内容的软件包确实可以工作:

  <files>
        <!-- Include everything in \build -->
    <file src="build\**" target="build" />
  </files>

Include build directory in nuget package using visual studio pack 使用Visual Studio Pack将构建目录包含在nuget包中

According to the document Including content in a package , you should use the properties <Pack>true</Pack> and <PackagePath>build\\</PackagePath> : 根据包含包中内容的文档,应使用属性<Pack>true</Pack><PackagePath>build\\</PackagePath>

If you want to copy all your content to only a specific root folder(s) (instead of content and contentFiles both), you can use the MSBuild property ContentTargetFolders, which defaults to "content;contentFiles" but can be set to any other folder names. 如果要将所有内容仅复制到一个特定的根文件夹(而不是同时复制content和contentFiles),则可以使用MSBuild属性ContentTargetFolders,该属性默认为“ content; contentFiles”,但可以设置为任何其他文件夹名。

PackagePath can be a semicolon-delimited set of target paths. PackagePath可以是以分号分隔的目标路径集。 Specifying an empty package path would add the file to the root of the package. 指定空的程序包路径会将文件添加到程序包的根目录。

So, you can change your ItemGroup like following: 因此,您可以按以下方式更改ItemGroup:

  <ItemGroup>
    <None Include="build\**" Pack="True" PackagePath="build\" />
  </ItemGroup>

Update: 更新:

I believe this is the same as what I added but in a different XML structure and without the Pack attribute 我相信这与我添加的内容相同,但是具有不同的XML结构并且没有Pack属性

The Pack attribute is the key point. Pack属性是关键。 It works fine with your XML structure and the Pack attribute. 它可以很好地与您的XML结构和Pack属性一起使用。 You should make sure you have the files in the build folder in your project folder : 您应该确保项目文件夹中的build文件夹中有这些文件:

在此处输入图片说明

Check my test demo below: 在下面查看我的测试演示:

在此处输入图片说明

Update2: UPDATE2:

Ah! 啊! You are using the .net framework project!! 您正在使用.net framework项目!! That the reason for this issue. 就是这个问题的原因。 This method is used for .net standard and .net core project by default and it not work for .net framework . 默认情况下,此方法用于.net standard.net core项目,不适用于.net framework To resolve this issue you have to use the .nupsec file, like you post in the question. 要解决此问题,您必须使用.nupsec文件,就像您在问题中发布的一样。

If you still want to include build directory in nuget package using visual studio pack , you need change your project type to SDK type: 如果您仍然想使用Visual Studio pack将构建目录包含在nuget包中,则需要将项目类型更改为SDK类型:

Check this document for some more details. 有关更多详细信息,请查看此文档

Then you can use the method, which we talked about before. 然后,您可以使用我们之前讨论过的方法。

Hope this helps. 希望这可以帮助。

The solution to this issue was to upgrade the project to SDK type (Xamarin binding projects by default use the old format but seem to work with the new type) and then use: 解决此问题的方法是将项目升级到SDK类型 (默认情况下,Xamarin绑定项目使用旧格式,但似乎可以使用新类型),然后使用:

<ItemGroup>
    <None Update="build\**">
        <IncludeInPackage>true</IncludeInPackage>
    </None>
</ItemGroup>

To include the build directory. 包括构建目录。 The alternative is using nuget pack . 另一种方法是使用nuget pack

When converting the project make sure to leave in the Xamarin import: 转换项目时,请确保保留Xamarin导入:

<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.ObjCBinding.CSharp.targets" />

Here's how my project file looks afterwards: 以下是我的项目文件的外观:

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
  <PropertyGroup>
    <PackageId></PackageId>
    <PackageVersion>3.3.2</PackageVersion>
    <ReleaseVersion>$(PackageVersion)</ReleaseVersion>
    <AssemblyVersion>$(PackageVersion)</AssemblyVersion>
    <Authors>Nick Brook</Authors>
    <Description></Description>
    <Copyright></Copyright>
    <PackageProjectUrl></PackageProjectUrl>
    <Summary></Summary>
    <PackageTags></PackageTags>
    <Title></Title>
    <PackageReleaseNotes>Initial Release</PackageReleaseNotes>
    <OutputType>Library</OutputType>
    <IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
    <OutputPath>bin\$(Configuration)</OutputPath>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <Optimize>true</Optimize>
    <PackageOutputPath>packed</PackageOutputPath>
    <PackOnBuild>true</PackOnBuild>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="Xamarin.iOS" />
  </ItemGroup>
  <ItemGroup>
    <ObjcBindingApiDefinition Include="ApiDefinition.cs" />
  </ItemGroup>
  <ItemGroup>
    <ObjcBindingCoreSource Include="Structs.cs" />
  </ItemGroup>
  <ItemGroup>
    <Compile Remove="Structs.cs" Condition=" '$(EnableDefaultCompileItems)' == 'true' " />
    <Compile Remove="ApiDefinition.cs" Condition=" '$(EnableDefaultCompileItems)' == 'true' " />
  </ItemGroup>
  <ItemGroup>
    <None Remove="packed\**" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Xamarin.Build.Download" Version="0.4.11" />
    <PackageReference Include="NuGet.Build.Packaging" Version="0.2.2" />
  </ItemGroup>
  <ItemGroup>
    <None Update="build\**">
      <IncludeInPackage>true</IncludeInPackage>
    </None>
  </ItemGroup>
  <Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.ObjCBinding.CSharp.targets" />
</Project>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM