让NuGet包输出文件 [英] Have a NuGet package output a file

查看:64
本文介绍了让NuGet包输出文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个已制成NuGet包的Visual Studio项目.该项目中包含一个文件(称为 SwaggerIndex.html ).我已将该文件设置为具有复制到输出目录"属性复制到如果更新则复制".(我需要将此文件复制到build上的build文件夹中.)

在该解决方案中,它可以正常工作.(我创建了另一个项目进行测试,当它引用我的具有 SwaggerIndex.html 的项目时,就可以将其输出到build文件夹.)

但是,当我将其打包到NuGet中并将其拉到另一个解决方案/项目中时, SwaggerIndex.html 文件不会在生成时输出.

我正在通过转到项目的"Package"(程序包)来制作我的NuGet程序包.属性标签,然后选择在构建时生成NuGet软件包".所有涉及的项目都在运行.Net Core 3.1.

如何获取我的NuGet软件包以在构建时创建我的 SwaggerIndex.html 文件(就像在普通项目中一样)?

解决方案

请尝试以下操作:

我有两种解决方案供您解决.

解决方案1 ​​

如果您只想在新的sdk项目( Net Core Net Standard 项目)中安装此nuget软件包,则可以使用此

1)将这些节点添加到您的 xxx.csproj 文件中:

 < ItemGroup><无包含="xxx \ SwaggerIndex.html(您项目中SwaggerIndex.html文件的路径)"Pack ="true"PackagePath ="contentFiles \ any \ any"< PackageCopyToOutput> true</PackageCopyToOutput></无></ItemGroup> 

2),然后重新打包您的nuget项目,在安装新版本之前,您应该首先

2),然后将这些内容添加到 SwaggerIndex.props 文件中,

 < Project><目标名称="CopyToOutputFolder";BeforeTargets ="Build"< ItemGroup><文件包含=" $(MSBuildThisFileDirectory).. \ File \ *.*></File></ItemGroup>< Copy SourceFiles ="@(文件)";DestinationFolder ="$(TargetDir)"</Copy></Target></Project> 

3)将它们添加到nuget项目的 xxx.csproj 文件中.

 < ItemGroup>< None Include =" SwaggerIndex.html"Pack ="true"PackagePath =文件"</None><无包含="build \ SwaggerIndex.props";Pack ="true"PackagePath ="build"</None></ItemGroup> 

4),然后重新打包您的nuget软件包,在安装此新版本的nuget软件包之前,您应该

此外,还有 解决方案

Please try these:

I have two solutions for you to solve the issue.

Solution 1

If you just want to install this nuget package only in new sdk projects(Net Core and Net Standard projects), you could use this

1) add these node in your xxx.csproj file:

<ItemGroup>
    <None Include="xxx\SwaggerIndex.html(the path of SwaggerIndex.html file in your project)" Pack="true" PackagePath="contentFiles\any\any">
        <PackageCopyToOutput>true</PackageCopyToOutput>
    </None>
</ItemGroup>

2) then repack your nuget project, and before you install the new version, you should first clean nuget caches first or just delete all cache files under C:\Users\xxx(current user)\.nuget\packages

Solution 2

If you want this nuget package to copy SwaggerIndex.html file in both Net Framework and Net Core projects, you should use this:

1) add a file called <package_id>.props file in your nuget project. You should note that if your nuget package named as SwaggerIndex.1.0.0.nupkg, you should name the file as SwaggerIndex.props file so that it will work.

In my side, I put it into a folder called build.

2) then add these content in SwaggerIndex.props file,

<Project>
    <Target Name="CopyToOutputFolder" BeforeTargets="Build">
        <ItemGroup>
            <File Include="$(MSBuildThisFileDirectory)..\File\*.*"></File>
        </ItemGroup>
        <Copy SourceFiles="@(File)" DestinationFolder="$(TargetDir)"></Copy>
    </Target>
</Project>

3) add these in xxx.csproj file of your nuget project.

<ItemGroup>
        <None Include="SwaggerIndex.html" Pack="true" PackagePath="File"></None>
        <None Include="build\SwaggerIndex.props" Pack="true" PackagePath="build"></None>   
</ItemGroup>

4) then repack your nuget package, before installing this new version of the nuget package, you should first clean all nuget caches first.

When you finishing installing the new version of the nuget package, click Build and the file will be copied into the main project.

Besides, there is also a similar issue about this.

这篇关于让NuGet包输出文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆