.NET 6项目发布时NuGet包中runtimeconfig.json等文件未复制的问题
解决.NET 6项目发布时NuGet包中runtimeconfig.json和deps.json未复制的问题
试试下面几个简便的方法,不用折腾.targets文件:
方法1:直接在项目文件里指定复制规则
打开你的
<ItemGroup> <Content Include="$(NuGetPackageRoot)\你的包名\包版本\lib\net6.0\MyHost.runtimeconfig.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> </Content> <Content Include="$(NuGetPackageRoot)\你的包名\包版本\lib\net6.0\MyHost.deps.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory> </Content> </ItemGroup>
记得把你的包名和包版本换成你实际用的NuGet包信息,比如MyHostPackage和1.0.0。
方法2:调整NuGet包结构(有权限改包的话)
如果你能修改这个NuGet包的打包配置,把runtimeconfig.json和deps.json移到contentFiles\any\net6.0目录下,然后在.nuspec文件里加上这两个文件的引用:
<files> <file src="lib\net6.0\MyHost.exe" target="lib\net6.0" /> <file src="lib\net6.0\MyHost.runtimeconfig.json" target="contentFiles\any\net6.0" /> <file src="lib\net6.0\MyHost.deps.json" target="contentFiles\any\net6.0" /> </files>
重新打包后,项目引用这个包时,这两个文件会自动被包含进去,发布时自然就复制到输出目录了。
方法3:用PostBuild事件手动复制
嫌改XML麻烦的话,直接在项目的PostBuild事件里加命令行复制:
xcopy "$(NuGetPackageRoot)\你的包名\包版本\lib\net6.0\MyHost.runtimeconfig.json" "$(OutDir)" /Y /R xcopy "$(NuGetPackageRoot)\你的包名\包版本\lib\net6.0\MyHost.deps.json" "$(OutDir)" /Y /R
同样替换包名和版本,这种方式适合快速临时解决问题,不用动项目配置文件的结构。
内容的提问来源于stack exchange,提问作者Mike Mozhaev
相关产品推荐
相关产品推荐

