【问题标题】:Create Custom NuGet Package In Visual Studio 2017在 Visual Studio 2017 中创建自定义 NuGet 包
【发布时间】:2017-03-01 00:34:11
【问题描述】:

我正在尝试通过 VS2017 创建自定义包,但到目前为止没有成功。我正在尝试将一些 .txt 文件添加到包的根目录,但它不起作用。

解决方案的结构:

ClassLibrary1.csproj
---> NugetContentFolder/Example1.txt

所需结构(Nuget):

ClassLibray1.dll
Example1.txt

我试试:

构建 -> 打包 ClassLibrary1

XML:

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

  <PropertyGroup>
    <TargetFrameworks>netstandard1.6;net45</TargetFrameworks>
    <Authors>A</Authors>
    <Company>B</Company>
    <Product>C</Product>
    <Copyright>E</Copyright>
    <PackageLicenseUrl>F</PackageLicenseUrl>
    <PackageProjectUrl>G</PackageProjectUrl>
    <PackageIconUrl>H</PackageIconUrl>
    <RepositoryUrl>I</RepositoryUrl>
    <RepositoryType>J</RepositoryType>
    <PackageTags>L</PackageTags>
    <PackageReleaseNotes>M</PackageReleaseNotes>
    <NeutralLanguage>en-US</NeutralLanguage>
    <Description>H</Description>
    <files>
      <file src="Folder1/Example1.txt" target="Example1.txt" />
    </files>
  </PropertyGroup>

  <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.6' ">
    <PackageReference Include="Newtonsoft.Json" Version="9.0.2-beta2" />
    <PackageReference Include="Microsoft.Extensions.DependencyModel" Version="1.0.1-beta-003206" />
    <PackageReference Include="System.Runtime.Loader" Version="4.0.0" />
    <PackageReference Include="System.Reflection.Extensions" Version="4.3.0" />
    <PackageReference Include="System.Reflection.TypeExtensions" Version="4.3.0" />
  </ItemGroup>

  <ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
    <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
    <PackageReference Include="Microsoft.AspNet.Razor" Version="3.0.0" />
    <Reference Include="System" />
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>

</Project>

我该怎么做?

最后,我发现将这些信息耦合到“csproj”中非常糟糕,在我看来,分离到另一个文件中并不困难。

【问题讨论】:

标签: customization nuget-package pack visual-studio-2017


【解决方案1】:

对我有用的是添加以下部分:

  <ItemGroup>
    <Content Include="..\..\LICENSE.txt" Link="LICENSE.txt">
      <PackagePath>LICENSE.txt</PackagePath>
      <IncludeInPackage>true</IncludeInPackage>
    </Content>
  </ItemGroup>

编辑:我找到了另一个更简单的解决方案,可以防止将文件添加到项目中:

<ItemGroup>
  <None Include="..\..\nuspec\install.ps1" Pack="true" PackagePath="tools" />
  <None Include="..\..\LICENSE.txt" Pack="true" PackagePath="" />
  <None Include="..\..\CHANGELOG.md" Pack="true" PackagePath="" />
  <None Include="..\libs\Interop\3.5\Interop.UIAutomationClient.dll" Pack="true" PackagePath="lib\net35" />
  <None Include="..\libs\Interop\4.0\Interop.UIAutomationClient.dll" Pack="true" PackagePath="lib\net40" />
  <None Include="..\libs\Interop\4.5\Interop.UIAutomationClient.dll" Pack="true" PackagePath="lib\net45" />
</ItemGroup>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-12
    • 1970-01-01
    • 1970-01-01
    • 2017-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多