2017-06-12 124 views
10

我最近搬到Visual Studio 2017社区版增加额外的文件到NuGet包。它有2个不错的新功能你如何在Visual Studio 2017年

  1. 你并不需要明确包括在的csproj源文件,它 自动执行此操作,
  2. 它可以直接建立的NuGet包。

我想将我的开放源码CodeFirstWebFramework DLL打包为nuget包。除了包含DLL之外,软件包还必须包含其他文件(包括.js,.tmpl,.css和.md文件)的整个目录树。

我如何告诉Visual Studio,我想包中包含该目录树?

从我发现哪些信息与广泛的搜索,并忽略所有过时的信息,涉及到文件添加到csproj,我能找到的所有信息是将它们放在一个contentFiles文件夹中,但这似乎不工作。

我的项目文件看起来像这样:

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

    <PropertyGroup> 
    <TargetFramework>net45</TargetFramework> 
    <GeneratePackageOnBuild>True</GeneratePackageOnBuild> 
    <Authors>Nikki Locke</Authors> 
    <Company>Trumphurst Ltd</Company> 
    <Description>Easy to use web server for building web apps that use sql databases generated from c# classes</Description> 
    <Copyright>2017 Trumphurst Ltd.</Copyright> 
    <PackageProjectUrl>https://github.com/nikkilocke/CodeFirstWebFramework</PackageProjectUrl> 
    <RepositoryUrl>https://github.com/nikkilocke/CodeFirstWebFramework</RepositoryUrl> 
    <RepositoryType>Github</RepositoryType> 
    <PackageTags>C# SQL Code First Web Server</PackageTags> 
    </PropertyGroup> 

    <ItemGroup> 
    <PackageReference Include="Markdig" Version="0.12.1" /> 
    <PackageReference Include="Mono.Data.Sqlite.Portable" Version="1.0.3.5" /> 
    <PackageReference Include="mustache-sharp" Version="0.2.10" /> 
    <PackageReference Include="MySql.Data" Version="6.9.9" /> 
    <PackageReference Include="Newtonsoft.Json" Version="10.0.2" /> 
    </ItemGroup> 

    <ItemGroup> 
    <Reference Include="System.Net" /> 
    <Reference Include="System.Web" /> 
    </ItemGroup> 

</Project> 

狂乱猜测我可能需要从冲突做,出过期的网络上的信息,我已经添加了以下内容:

<ItemGroup> 
    <Content Include="contentFiles/**/*.*" copyToOutput="true"> 
     <IncludeInPackage>true</IncludeInPackage> 
    </Content> 
    </ItemGroup> 
现在

.nupkg文件具有contentFiles文件夹内幕它的内容(在两个地方,一个content文件夹和文件夹contentFiles

然而,当我在另一个项目中安装包,内容文件不会出现,尽管它们在project.assets.json文件中obj文件夹中列出。

+1

*您并不需要明确包括在的csproj源文件,它自动执行此操作,并且可以直接建立的NuGet包* - 你在哪里读的?这个doco(这是一个.NET核心的例子,不知道你的目标是否完整)有几个步骤https://docs.microsoft.com/en-us/nuget/guides/create-net-standard-packages-vs2017有您添加了DLL到项目和生成输出目录或是在csproj中引用? –

+0

例如http://www.natemcmaster.com/blog/2017/03/09/vs2015-to-vs2017-upgrade/ –

+0

“您是否已经将DLL添加到项目和生成输出目录中,还是在csproj中引用?” - 不明白这个问题。什么DLL? –

回答

3

我现在又改变了我的项目文件,所以它现在读取:

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

    <PropertyGroup> 
    <TargetFramework>net45</TargetFramework> 
    <GeneratePackageOnBuild>True</GeneratePackageOnBuild> 
    <Authors>Nikki Locke</Authors> 
    <Company>Trumphurst Ltd</Company> 
    <Description>Easy to use web server for building web apps that use sql databases generated from c# classes</Description> 
    <Copyright>2017 Trumphurst Ltd.</Copyright> 
    <PackageProjectUrl>https://github.com/nikkilocke/CodeFirstWebFramework</PackageProjectUrl> 
    <RepositoryUrl>https://github.com/nikkilocke/CodeFirstWebFramework</RepositoryUrl> 
    <RepositoryType>Github</RepositoryType> 
    <PackageTags>C# SQL Code First Web Server</PackageTags> 
    </PropertyGroup> 

    <ItemGroup> 
    <PackageReference Include="Markdig" Version="0.12.1" /> 
    <PackageReference Include="Mono.Data.Sqlite.Portable" Version="1.0.3.5" /> 
    <PackageReference Include="mustache-sharp" Version="0.2.10" /> 
    <PackageReference Include="MySql.Data" Version="6.9.9" /> 
    <PackageReference Include="Newtonsoft.Json" Version="10.0.2" /> 
    </ItemGroup> 

    <ItemGroup> 
    <Reference Include="System.Net" /> 
    <Reference Include="System.Web" /> 
    </ItemGroup> 

    <ItemGroup> 
    <Content Include="contentFiles/**/*.*" copyToOutput="true"> 
     <IncludeInPackage>true</IncludeInPackage> 
     <CopyToOutput>true</CopyToOutput> 
     <BuildAction>Content</BuildAction> 
     <copyToOutput>true</copyToOutput> 
     <CopyToOutputDirectory>Always</CopyToOutputDirectory> 
    </Content> 
    </ItemGroup> 

    <ItemGroup> 
    <Compile Remove="Phone\**" /> 
    <EmbeddedResource Remove="Phone\**" /> 
    <None Remove="Phone\**" /> 
    </ItemGroup> 

</Project> 

的contentFiles现在成功地复制到相同名称的文件夹(即contentFiles)在下载NuGet包的任何项目 - 不确定哪个指令有效,但其中有一个是。

内容不会自动复制到编译项目的输出文件夹,遗憾的是 - 建议表示欢迎。

1

包装在“内容”和“IncludeInPackage”是不够好,文件(县)复制到该包。