Vek*_*ksi 7 .net nuget .net-standard
我正在创建具有以下想法的NuGet包:
这个想法不是要嵌入本机资源然后提取它们,而是与使用它们的.NET库一起分发。但是,我遇到了一些我想问的问题。
1.外部依赖关系的根是否有一个公认的约定?目前,我的结构是:
.\Solution.sln
.\Solution.nuspec
.\runtimes\win-x64\native\<.exe and .dll>
.\Project\Project.csproj
Run Code Online (Sandbox Code Playgroud)
.NET Standard 2.0库项目编译为Project\bin\Debug\netstandard2.0。我想知道根是否还有其他约定或名称。除了其他资源和GitHub项目,我还阅读了创建NuGet包的项目。
2.以.nuspec其他方式获取文件非常普通,我想知道如何安排文件引用?我阅读了Nuspec更换令牌上的说明,并且在.nuspec文件中有一节告诉您:
<files>
<file src="bin/$configuration$/$id$.pdb" target="lib/netstandard20" />
<file src="bin/$configuration$/$id$.dll" target="lib/netstandard20" />
<file src="runtimes/win-x64/native/.exe" target="runtimes/win-x64/native/.exe" />
<file src="runtimes/win-x64/native/.dll" target="runtimes/win-x64/native/.dll" />
</files>
Run Code Online (Sandbox Code Playgroud)
但是不包含本机文件。当我尝试以开始设置相对路径时也是如此..\(我仍然可能会遇到这个错误,可能会睡一会再重试)。
3.我是否应该包括某种.props文件,然后对使用Nuget库的人正确地包含包装器和本机资源?应该进行设置,以包括并设置所有本机资源的两个文件,以便将它们与其他构建工件一起复制到项目输出中。
4.我应该做些特别的安排Project.csproj吗?也许更好的问题是,我应该注意一些健壮的做法吗?我看到有一些问题和答案,例如https://github.com/aspnet/websdk/issues/204#issuecomment-302482115。或者实际上是将本机dll自动复制到Visual Studio中引用项目的bin文件夹中,也自动从Nuget Package中提取本机和托管DLL。我应该提到的Project.csproj只是我设置了:
<PropertyGroup>
<RuntimeIdentifiers>win-x64;osx.10-11-x64;ubuntu.16.04-x64;debian.8-x64</RuntimeIdentifiers>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
编辑: Do!我正在尝试通过创建包dotnet pack .\Project\Project.csproj,而不使用该.nuspec文件。也许一种好方法是使用.net Core的csproj格式的其他说明中所述的Nuget元数据工具。
编辑2:似乎试图打包通过.csproj存在很多问题,更多问题请参见https://github.com/NuGet/Home/issues/2372。
编辑3:在VS 2017中,似乎该Package选项卡是添加详细信息的最佳方法。然后.csproj需要像
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RuntimeIdentifiers>win-x64;debian-x64</RuntimeIdentifiers>
</PropertyGroup>
<ItemGroup>
<Content Include="lib\runtimes\win-x64\native\.exe">
<PackagePath>lib/runtimes/win-x64/native/.exe</PackagePath>
<Pack>true</Pack>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
本机资源包含在NuGet程序包中,但无法正确还原。
编辑4:其他人也有类似的问题。更多链接和原理请参见https://github.com/NuGet/Home/issues/6645。
编辑5:使用上述结构,需要添加的最后一件事是在根目录下添加一个文件,如下所示:lib
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)../../lib/runtimes/win-x64/native/.exe">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>.exe</Link>
<Visible>false</Visible>
</Content>
</ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
然后到Project.csproj里面ItemGroup添加
<Content Include="lib/{your_libraryname}.targets">
<PackagePath>build/netstandard2.0/</PackagePath>
<Pack>true</Pack>
</Content>
Run Code Online (Sandbox Code Playgroud)
有了这些,这似乎已得到解决。
| 归档时间: |
|
| 查看次数: |
1771 次 |
| 最近记录: |