ueb*_*ebe 3 c# csproj visual-studio nuget .net-core
我想在.NET Core项目(.csproj)中使用一小段源代码(例如帮助程序类).此时,我根据不同的博客文章和官方nuget文档以多种不同的方式将源代码与NuGet打包在一起.我使用了一个nuspec文件来控制我的源文件最终会在nuget包中的位置,例如:
<files>
<file src="*.cs" target="content/LruCache" />
<file src="*.cs" target="contentFiles/cs/any/LruCache" />
</files>
Run Code Online (Sandbox Code Playgroud)
我没有包含任何msbuild目标文件或安装脚本.
每当我将NuGet包安装到.NET Core项目(https://docs.microsoft.com/en-us/dotnet/core/tools/csproj)时,我根本就没有得到任何东西.我的项目中不会包含任何源文件.我为<PackageReference/>.csproj(PrivateAssets等)中的节点尝试了不同的设置但没有成功.
这有可能吗?如果是这样,应该怎么做?
背景:
这样做的原因是某种钻石问题,我们有项目B和C都使用辅助类A和第三个项目D使用B和C.在这种情况下我不想处理汇编版本冲突时在B和C中使用了不同(不兼容)的A版本.
这有可能吗?如果是这样,应该怎么做?
答案是肯定的.由于您测试项目类型是.net核心.你应该使用contentFiles而不是content.content用于packages.config.检查使用contentFiles元素查找内容文件和博客NuGet ContentFiles Demystified以获取更多详细信息.
所以你的.nuspec文件应该是:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MyTestCore</id>
<version>5.0.0</version>
<authors>TestContentFile</authors>
<owners>TestContentFile</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>Package Description</description>
<contentFiles>
<files include="any/any/Test.cs" buildAction="content" flatten="true" copyToOutput="true"/>
</contentFiles>
</metadata>
<files>
<file src="contentFiles/any/any/Test.cs" target="contentFiles/any/any/LruCache" />
</files>
</package>
Run Code Online (Sandbox Code Playgroud)
nuget包应该看起来像:
注意:创建新包时,不要忘记在C:\Users\<UserName>\.nuget\packages文件夹中删除此包的nuget缓存,否则,它始终安装旧包.
使用此方法,源文件将包含在项目中.
希望这可以帮助.
| 归档时间: |
|
| 查看次数: |
1286 次 |
| 最近记录: |