我将在这里提出几个问题...首先,使用NuGet可以从几个DLL创建一个包吗?没有visual studio项目,只有命令行和一些预编译的DLL文件.
第二,假设这是可能的,为什么我不断得到"lib文件夹之外的程序集"警告?我已经尝试了所有我能想到的关联程序集将自己添加为NuGet包内的引用.
我的文件结构如下所示
Root
- File1.dll
- lib
- File2.dll
- File3.dll
Run Code Online (Sandbox Code Playgroud)
当我告诉NuGet使用像这样的.nuspec打包它
<?xml version="1.0"?>
<package >
<metadata>
<id>File1.dll</id>
<version>1.0.0</version>
<authors>thisguy</authors>
<owners>thisguysmom</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>This is some library</description>
<releaseNotes>Porting to NuGet</releaseNotes>
<copyright>Copyright 2012</copyright>
<references>
<reference file="File2.dll" />
<reference file="File3.dll" />
</references>
</metadata>
</package>
Run Code Online (Sandbox Code Playgroud)
我收到了警告.从我正在阅读的内容来看,我甚至不必在任何项目中定义引用节点,因为lib文件夹项应该自动添加为引用?
有没有人了解这个NuGet一塌糊涂?
我正在尝试为依赖于ghostscript的库创建一个Nuget包,因此引用了gsdll32.dll - 一个非托管库.我不能只包括一个标准的dll参考.我在哪里把它放在nuget目录结构中?
我正在创建具有以下想法的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,而不使用该 …
我正在 .NET Core 中编写一个应用程序,该应用程序依赖于使用[DllImport]. 我有适用于 win-x64、win-x86 和 linux-x64 的本地编译库工件。
我的项目结构是这样的:
MyApp
|--Main.cs
|--runtimes
|--win-x86
|--native
|--somelibrary.dll
|--win-x64
|--native
|--somelibrary.dll
|--linux-x64
|--native
|--libsomelibrary.so
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序时,我得到了 DLL not found 异常。
我曾尝试在此处使用 MSBuild 目标解决方案,但这仅dll在编译时将一个复制到主输出文件夹。但是,我希望输出以与上面的 runtimes 文件夹相同的结构在输出文件夹中包含所有三个本机库,并将兼容本机库的选择留给 .NET Core 运行时主机。
因此,如果用户在 Windows x86 中运行该应用程序,它将使用 win-x86,依此类推。
我注意到,当我从 NuGet引用像SkiaSharp这样的原生包装器时,它实际上会很好地集成到我的应用程序中,并将包含运行时文件夹结构中的所有资产,以便在运行时在多个环境中工作。我怎样才能做到这一点?
编辑:
我最终为本地库绑定创建了一个 nuget 包,并在我的其他项目中引用了 nuget。
上一次我不得不找出如何从Nuget包中提取一些文件的过程至少花了我6个月的时间,但最终我设法找到了解决方案。
事实是,此解决方案假定我有一个.nupkg文件并手动添加一个.targets文件以执行提取过程。
现在,情况有所不同:
.nupgk文件,我们使用以下命令在VSTS服务器上自动生成一个文件:dotnet pack命令。然后我们从Nuget服务器中使用软件包这是我的 ProjectName.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<Authors>Jérôme MEVEL</Authors>
<Version>1.0.3</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<!-- This answer got many votes on a Github thread so I tried just in case -->
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<!-- Just trying that too-->
<IncludeBuildOutput>true</IncludeBuildOutput>
<IncludeContentInPack>true</IncludeContentInPack>
<!-- I wanted to see the full generated Nuget package -->
<IncludeSource>true</IncludeSource>
<!-- desperate attempt -->
<TargetsForTfmSpecificBuildOutput>GetMyPackageFiles</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="1.50.5" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" />
<PackageReference …Run Code Online (Sandbox Code Playgroud)