问题描述
我有一个已制作成 NuGet 包的 Visual Studio 项目.该项目中有一个文件(称为 SwaggerIndex.html
).我已将该文件设置为复制到输出目录".属性为如果更新则复制".(我需要将此文件复制到构建时的构建文件夹.)
在那个解决方案中它工作得很好.(我创建了另一个项目来测试它,当它引用我的具有 SwaggerIndex.html
的项目时,它将它输出到构建文件夹就好了.)
但是,当我将其打包到 NuGet 并将其拉入另一个解决方案/项目时,SwaggerIndex.html
文件不会在构建时输出.
我正在通过转到项目的包"来制作我的 NuGet 包.属性选项卡并选择在构建时生成 NuGet 包".所有涉及的项目都运行.Net Core 3.1.
如何让我的 NuGet 包在构建时创建我的 SwaggerIndex.html
文件(就像它只是一个普通项目时那样)?
请试试这些:
我有两个解决方案供您解决问题.
解决方案 1
如果你只想在新的 sdk 项目(Net Core
和 Net Standard
项目)中安装这个 nuget 包,你可以使用这个
1) 在您的 xxx.csproj
文件中添加这些节点:
<None Include="xxxSwaggerIndex.html(你的项目中SwaggerIndex.html文件的路径)";包=真"PackagePath=contentFilesanyany"><PackageCopyToOutput>true</PackageCopyToOutput></无></项目组>
2) 然后重新打包您的 nuget 项目,在安装新版本之前,您应该先
2) 然后将这些内容添加到 SwaggerIndex.props
文件中,
<目标名称=CopyToOutputFolder"BeforeTargets=构建"><项目组><File Include="$(MSBuildThisFileDirectory)..File*.*></File></项目组><Copy SourceFiles="@(File)";DestinationFolder=$(TargetDir)"></Copy></目标></项目>
3) 将这些添加到您的 nuget 项目的 xxx.csproj
文件中.
<None Include="SwaggerIndex.html";包=真"PackagePath=文件">无><None Include="buildSwaggerIndex.props";包=真"PackagePath=build"></项目组>
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 包输出一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!