【发布时间】:2016-09-23 01:35:05
【问题描述】:
我在其中创建了一个 c# 项目,我引用了 system.windows.interactivity.dll。
我想知道的是如何设置项目,以便在构建 *.exe 时得到这种结构:
Program Folder
program.exe
Libraries Folder
system.windows.interactivity.dll
我通过在解决方案文件夹下放置一个“库”文件夹进行了一些实验,使其与项目文件夹处于同一级别。这在“..\Libraries\system.windows.interactivity.dll”的 csproj 文件中给出了一个相对路径,但这不是解决方案,因为当我编译它时,它会使用 exe 将 dll 复制到调试文件夹中并保留它“同级”路径结构。
我怎样才能改变一些东西,以便它在另一个目录中放置和引用 dll?
[更新]
所以我在我的项目中修改了以下内容:
1:将参考 system.windows.interactivity.dll 上的“复制本地”属性更改为 False。
2:在csproj文件中添加以下代码,检查输出目录上方是否存在Libraries文件夹,如果不存在则创建复制dll。
<Target Name="BeforeBuild">
<MakeDir Directories="$(OutDir)..\Libraries"
Condition="!Exists('$(OutDir)..\Libraries')" />
<Copy SourceFiles="..\Libraries\System.Windows.Interactivity.dll"
DestinationFolder="$(OutDir)..\Libraries"
ContinueOnError="True" />
</Target>
3。将以下代码添加到 App.config 中,为应用添加另一个位置以搜索 dll。
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="..\Libraries"/>
</assemblyBinding>
</runtime>
</configuration>
我的发现:
构建应用程序后,所有文件都在我想要的位置,就像我原始帖子中的结构一样。当我尝试从输出目录运行 exe 时,它找不到 dll。
[/更新]
【问题讨论】:
-
你不能 - windows 有一个特定的顺序来寻找 dll。
标签: c# visual-studio-2013 relative-path buildconfiguration dll-reference