English 中文(简体)
在什么地方为未管理的图书馆提供lls?
原标题:Where to place dlls for unmanaged libraries?

我正试图为依赖影像的图书馆制作一个Nuget包裹,因此,参考资料格斯德尔-未经管理的图书馆。 我只能把标准指指指包括在内。 我在什么地方把这一点放在了核心结构中?

问题回答

在包件中添加一个<代码>build ,如果包件如贴上<代码>MyPackage<>/code>,则将一个名为<代码>MyPackage.targets的MSBuild指标文档加到这个夹中。 重要的是,<代码>.targetsfile上的名称与.nuspec文档相同。 在<代码>.nuspec 你们必须拥有这样一个部分:

<files>
    <file src="lib*.*" target="lib" />
    <file src="buildMyPackage.targets" target="build" />
</files>

这将在项目档案中添加一个MSBuild元素,注明.targets文档。

此外,只有登记有管理的货单,增加一款:

<references>
    <reference file="MyManaged.dll" />
</references>

The .targets file should look what such as:

<?xml version="1.0" encoding="utf-8"?> 
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
  <Target Name="CopyMyPackageFiles" AfterTargets="AfterBuild"> 
    <ItemGroup> 
      <MyPackageFiles Include="$(MSBuildThisFileDirectory)..lib*.*"/> 
    </ItemGroup> 
    <Copy SourceFiles="@(MyPackageFiles)" DestinationFolder="$(OutputPath)" > 
    </Copy> 
  </Target> 
</Project>

现在,all文档——包括未经管理的档案——将在建筑后复制项目产出夹(如 in)。

以上提到可以发挥作用,但事实上,它篡改了你的职位,以推倒档案,如果你有情况,这实际上不可能解决你的问题。

我们所持有的问题不能登记在册,而必须与另一个DL同时存在,后者需要由Nget 登记,因此需要在校准目录中登记,但无需登记。

The nuspec reference now allows you to specify which DLLs in the lib directory get explicitly registered in the visual studio project now, you simply need to add into your nuspec file in the metadata area an explicit references list (if this does not exist the default behavior of nuget is to attempt to register everything under lib).

Here is an example nuspec file of what I mean:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
    <metadata>
        <id>SomePackageID</id>
        <version>1.0.1</version>
        <title>Some Package Title</title>
        <authors>Some Authors</authors>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>Blah blah blah.</description>
        <references>
            <reference file="ceTe.DynamicPDF.Rasterizer.20.x86.dll" />          
        </references>
    </metadata>
    <files>
        <file src="\SomeNetworkLocationceTe.DynamicPDF.Rasterizer.20.x86.dll" target="libceTe.DynamicPDF.Rasterizer.20.x86.dll" />
        <file src="\SomeNetworkLocationDPDFRast.x86.dll" target="libDPDFRast.x86.dll" />
    </files>
</package>

如你所知,ceTe.DynamicPDF.Rasterizer.20.x86.dll需要登记,但DPDFRast.x86.dll 仅需要在该名录中保存,以支持其他DLL和赢得的笔记,但通过一些动态参考资料,最终将复制到目的地bin目录,因为视觉演播室认为第一个DLL取决于第二个。

The original nuspec reference

我基本上用拉尔斯·迈克尔的方法开展工作,但我需要补充的是詹姆斯·埃比的答复。 视觉演播室试图在我的<代码>lib目录中登记所有批次,因此,我增加了一个<条码>优惠/代码”的元数据元件,以显示它只登记管理批次:

<references>
    <reference file="FANNCSharp.dll" />          
</references>

也是

<MyPackageFiles Include="$(MSBuildProjectDirectory)..PackagesMyPackagelib*.*"/>

我先尝试了我的包裹<代码>FANNCSharp-x64,但需要全方位名称:FANNCSharp-x64.0.1.4

One problem I had was that the packages path wasn t always in the same place relative to the project file. The following worked for me:

  1. Within the NuGet package, place your unmanaged DLLs in the lib ative folder.

  2. Add the following script to the tools folder:

安装。 页: 1

#This script creates or updates a PackagesPath property in the project file
param($installPath, $toolsPath, $package, $project)

$project.Save()

#Load the csproj file into an xml object
[xml] $xml = Get-Content -path $project.FullName

#grab the namespace from the project element 
$nsmgr = New-Object System.Xml.XmlNamespaceManager -ArgumentList $xml.NameTable
$nsmgr.AddNamespace( a ,$xml.Project.GetAttribute("xmlns"))

#find or create the property
$property = $xml.Project.SelectSingleNode("//a:PropertyGroup//a:PackagesPath", $nsmgr)
if (!$property)
{
    $property = $xml.CreateElement("PackagesPath", $xml.Project.GetAttribute("xmlns"))
    $propertyGroup = $xml.CreateElement("PropertyGroup", $xml.Project.GetAttribute("xmlns"))
    $propertyGroup.AppendChild($property)
    $xml.Project.InsertBefore($propertyGroup, $xml.Project.ItemGroup[0])
}

#find the relative path to the packages folder
$absolutePackagesPath = (get-item $installPath).parent.FullName
push-location (split-path $project.FullName)
$relativePackagesPath = Resolve-Path -Relative $absolutePackagesPath
pop-location

#set the property value
$property.InnerText = $relativePackagesPath

#save the changes.
$xml.Save($project.FullName)
  1. Add a targets file to the build folder. (Change "MyPackage" to the name of your package). Using a unique name for the target, like "CopyMyPackage", avoids conflicts with other packages trying to define the "AfterBuild" target. This targets file makes use of the $(PackagesPath) property defined by the above script.

MyPackage.targets

<?xml version="1.0" encoding="utf-8"?> 
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
  <Target Name="CopyMyPackage" AfterTargets="AfterBuild"> 
    <ItemGroup> 
      <MyPackageSourceFiles Include="$(PackagesPath)MyPackage.*lib
ative*.*"/> 
    </ItemGroup> 
    <Copy SourceFiles="@(MyPackageSourceFiles)" DestinationFolder="$(OutputPath)" > 
    </Copy> 
  </Target> 
</Project>
  1. Finally, add a "MyPackageReadMe.txt" to the Content folder. This will enable the package to install.

另见:

页: 1 如果你知道贵国的本地法典目标是哪一个运行时间的平台,那么核心就是直截了当的。 您可以注意到,在......中,有一只称为“营业时间”。 当你建造时,网络核心在双树下建树。 它看着这样的情况:

“runtime

这些夹子的设计是为了打上任何平台,包括无管理的/有代表性的DLLs。

在你的NuGet一揽子计划中,在“Files”栏下增加以下内容:

<file src="[source path for file in package]" target="runtimes[platform]
ative[file name]" />

在实施申请时,操作时间环境将寻找相应的平台名录中未管理的lls。

如果你想要把多个平台作为目标,就只能为每个平台增加另一个文档输入。





相关问题
Combo box inside of list control? (Unmanaged C++)

I m using unmanaged C++ and I was wondering if I could embed a combo box inside a column of my List View. I have tried googling for information, however I keep finding C# articles on the subject. It ...

NetUserModalsGet() returns strings incorrectly for C#.NET

EDIT: Yet another followup at https://stackoverflow.com/questions/1799742/shouldnt-netusermodalsget-tell-me-what-domain-a-machine-is-part-of-and-where Thanks to Gonzalo s help, I m able to use the ...

How to set the culture info in unmanaged C++?

I got a program written in unmanaged C++, I need to get the cultural info from the system and set that info to the current execution thread in my c++ application. Thanks.

C# delegate with string reference to c++ callback

I wrote a C# application that uses an unmanaged c++ dll via managed c++ dll. In the unmanaged dll, there s a callback that one of its params is std::string&. I can t seem to find the right way to ...

C++ Access to command line arguments outside main?

I have a couple command line apps that both end up calling into com objects. Rather than adding new interface to these com objects, can they access the parameters passed from the command line? Edit: ...

AccessViolation when calling unmanaged dll

When calling an unmanaged Dll from a c# application I get an AccessViolationException. The strange thing is that the exported function has no arguments, so the problem is not in the Marshalling of ...