先のフォルダにDLLをコピーするVSを伝えるには、いくつかの方法があります。
1.Add DLLプロジェクトのリソースとしては。 dllが新しい場合はVSにコピーします。
2. dllプロジェクトを参照する新しいプロジェクトを追加し、OutDirを目的のフォルダに設定します。このプロジェクトはdllをコピーするだけです。 PreBuildEvent 4.Use
vcxprojファイル内PostBuildEvent 3.Use
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
</ClCompile>
<Link>
</Link>
<PostBuildEvent>
<Command>
echo off
mkdir "$(ProjectDir)..\..\bin\$(Configuration)\"
copy "$(OutDir)xxx.dll" "$(ProjectDir)..\..\lib\$(Configuration)\"
echo on
</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
vcxprojファイル内
5.Use CustomBuild vcxprojファイル内
<ItemGroup>
<CustomBuild Include="..\..\xxx.dll">
<FileType>Document</FileType>
<Command>
call mkdir "$(OutDir)" 2>nul &
copy /Y "..\..\xxx.dll" "$(OutDir)xxx.dll"
</Command>
<Message>Copying xxx.dll to $(OutDir)\xxx.dll</Message>
<Outputs>$(OutDir)\xxx.dll</Outputs>
</CustomBuild>
</ItemGroup>
メイク6.Use makefileにdllをコピーします。そしてコピージョブを行う
7.Write batファイルを構築し、またからDLLをダウンロードすることができますPythonなど3-6
8.Useスクリプト、のようにbatファイルを呼び出すためにNMAKEを使用インターネット。そして、3-6のようにpyファイルを呼び出します。
は、Gradleのように、ツールはあまりにも助けることができる構築9.Other
10.MakeそれNuGetプラグイン
11.Sometimes私はバットを書き、手動でバットを実行します。
アップデート01(自己抽出DLLの例):マネージDLLのリソース
2.Addこのinit()メソッドとして
1.AddあなたネイティブDLL
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace DllSelfExtract
{
public class SelfExtract
{
public static void Init()
{
String managedDllPath = System.Reflection.Assembly.GetExecutingAssembly().CodeBase;
String nativeDllPath = managedDllPath.Replace("file:///", "").Replace("DllSelfExtract.DLL", "TestDll.dll");
if(!File.Exists(nativeDllPath))
{
Stream dllIn = Assembly.GetExecutingAssembly().GetManifestResourceStream("DllSelfExtract.TestDll.dll");
if (dllIn == null) return;
using (Stream outFile = File.Create(nativeDllPath))
{
const int sz = 4096;
byte[] buf = new byte[sz];
while (true)
{
int nRead = dllIn.Read(buf, 0, sz);
if (nRead < 1)
break;
outFile.Write(buf, 0, nRead);
}
}
}
//LoadLibrary Here
}
}
}
3 。
1.Create新しいNuGetプロジェクト
2.Placeの管理:あなたのマネージDLLを使用するプロジェクトでは、最初のinit()メソッド
SelfExtract.Init();
アップデート02(NuGet例)を呼び出します/ libディレクトリのアセンブリ
3.非管理共有ライブラリおよび関連ファイルを/ buildサブディレクトリに配置し、管理されていないすべての* .dllの名前を* .dl_
に変更します10 4.Add以下の内容のようなもので/ buildサブディレクトリ内のカスタム.targetsファイル:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<AvailableItemName Include="NativeBinary" />
</ItemGroup>
<ItemGroup>
<NativeBinary Include="$(MSBuildThisFileDirectory)*">
<TargetPath></TargetPath>
</NativeBinary>
</ItemGroup>
<PropertyGroup>
<PrepareForRunDependsOn>
$(PrepareForRunDependsOn);
CopyNativeBinaries
</PrepareForRunDependsOn>
</PropertyGroup>
<Target Name="CopyNativeBinaries" DependsOnTargets="CopyFilesToOutputDirectory">
<Copy SourceFiles="@(NativeBinary)"
DestinationFiles="@(NativeBinary->'$(OutDir)\%(TargetPath)\%(Filename).dll')"
Condition="'%(Extension)'=='.dl_'">
<Output TaskParameter="DestinationFiles" ItemName="FileWrites" />
</Copy>
<Copy SourceFiles="@(NativeBinary)"
DestinationFiles="@(NativeBinary->'$(OutDir)\%(TargetPath)\%(Filename).%(Extension)')"
Condition="'%(Extension)'!='.dl_'">
<Output TaskParameter="DestinationFiles" ItemName="FileWrites" />
</Copy>
</Target>
</Project>
5.Addが
<files>
<file src="lib\" target="lib" />
<file src="tools\" target="tools" />
<file src="content\" target="content" />
<file src="build\" target="build" />
</files>
6 Package.nuspecにビルドフォルダのルールを構築。パッケージを作る
7.あなたの他のC#プロジェクトでは、このNuGetパッケージを追加するだけです。
[Visual StudioでDLLの依存関係をコピーする](http://stackoverflow.com/questions/1043913/copying-a-dlls-dependencies-in-visual-studio)というタイトルの記事は役に立ちますか? –
私はこれが私が必要としているのではないかと心配しています。 Managed.dllとNative.dllを配布したいです。ライブラリのユーザーがManaged.dllを参照すると、プロジェクトのbinフォルダにローカルにコピーされたNative.dllが必要になります。 – Trifon