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

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

问题描述

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

在那个解决方案中它工作得很好.(我创建了另一个项目来测试它,当它引用我的具有 SwaggerIndex.html 的项目时,它将它输出到构建文件夹就好了.)

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

我正在通过转到项目的包"来制作我的 NuGet 包.属性选项卡并选择在构建时生成 NuGet 包".所涉及的所有项目都在运行 .Net Core 3.1.

如何让我的 NuGet 包在构建时创建我的 SwaggerIndex.html 文件(就像它只是一个普通项目时一样)?

解决方案

请试试这些:

我有两个解决方案供您解决问题.

解决方案 1

如果你只想在新的 sdk 项目(Net CoreNet Standard 项目)中安装这个 nuget 包,你可以使用这个

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

<None Include="xxxSwaggerIndex.html(你项目中SwaggerIndex.html文件的路径)"包=真";PackagePath="contentFilesanyany"><PackageCopyToOutput>true</PackageCopyToOutput></无></项目组>

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

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

<项目><目标名称=CopyToOutputFolder";BeforeTargets="构建"><项目组><文件包含="$(MSBuildThisFileDirectory)..File*.*></File></项目组><复制源文件=@(文件)"DestinationFolder=$(TargetDir)"></Copy></目标></项目>

3) 将这些添加到您的 nuget 项目的 xxx.csproj 文件中.

<无包含=SwaggerIndex.html";包=真";PackagePath=文件"></None><无包含=buildSwaggerIndex.props";包=真";PackagePath="build"></None></项目组>

4)然后重新打包你的nuget包,在安装这个新版本的nuget包之前,你应该

此外,还有 一个类似的问题关于这个.

I have a Visual Studio project that I have made into a NuGet package. The project has a file in it (called SwaggerIndex.html). I have set that file to have the "Copy to Output Directory" property to "Copy if newer". (I need this file to copy to the build folder on build.)

In that solution it works just fine. (I created another project to test it, and when it references my project that has the SwaggerIndex.html, it outputs it to the build folder just fine.)

However, when I package it into a NuGet and pull it into another solution/project, the SwaggerIndex.html file is not output on build.

I am making my NuGet package by going to the project's "Package" properties tab and selecting "Generate NuGet package on build". All projects involved are running .Net Core 3.1.

How can I get my NuGet Package to create my SwaggerIndex.html file on build (like it does when it is just a normal project)?

解决方案

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="xxxSwaggerIndex.html(the path of SwaggerIndex.html file in your project)" Pack="true" PackagePath="contentFilesanyany">
        <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:Usersxxx(current user).nugetpackages

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="buildSwaggerIndex.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天全站免登陆