我正在开发一个C# WinForms项目,该项目目前正在VS 2017中开发,不过,它将使用Mono框架(MonoRuntime
)部署在一个带有Ubuntu16.04LTS的Linux机器上。
我在我的项目中引用了EmguCV v3.2
和SQLite
。这两个程序集都是.NET托管程序集,它们依赖于自己的本机库(EmguCV
使用cvextern.dll
,SQLite
使用SQLite.Interop.dll
)。
由于这个应用程序将部署在Linux机器上,我已经成功地为它们编译并构建了.so
库文件(准确地说,是libcvextern.so
和libSQLite.Interop.so
)。
为了让我的应用程序在Windows上工作,两个.so
文件是多余的,而当我的应用程序在Mono下运行时,它们是必需的(而且它们必须总是在执行目录中!)
我的问题是,我想让VisualStudio2017或MonoDevelop理解,如果我正在构建.dll
(或者调试/发布),我需要将.dll
文件复制到输出目录( or )中,与Linux上的.so
文件类似。你是怎么处理这个的?
那么,如何正确设置vs2017和MonoDevelop都尊重的编译后事件,即它们在构建时标识底层当前操作系统并将各自的库文件复制到输出目录中?
对于任何英语语法问题,我都很抱歉,我不是本地人。
任何指点都很感激!
发布于 2018-08-10 10:21:13
好的,我已经分三个步骤解决了这个问题(在搜索了几个小时之后)。
如前所述,如果项目是在Windows上构建的(调试/发布),我的要求是将.dll
文件复制到输出目录,如果项目是在.so
上使用MonoDevelop构建的(调试/发布),则复制MonoDevelop对应的libs。
Add Existing Item
-> Add as Link
而不是Open
(找到这个from here)。Condition
文件中使用了ItemPropertyGroup
中的.csproj
属性。我所做的是:如果基本操作系统是.dll
,我将包括一个.so
文件,如果是linux,则包含两个.so
文件,这是我在.csproj
文件中修改的配置。
<ContentWithTargetPath Include="references\libDependencies\linux64\libcvextern.so" Condition=" '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' ">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>libcvextern.so</TargetPath>
</ContentWithTargetPath>
<ContentWithTargetPath Include="references\libDependencies\linux64\libSQLite.Interop.so" Condition=" '$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' ">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>libSQLite.Interop.so</TargetPath>
</ContentWithTargetPath>
<ContentWithTargetPath Include="references\libDependencies\win64\cvextern.dll" Condition=" '$(OS)' == 'Windows_NT' ">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<TargetPath>cvextern.dll</TargetPath>
</ContentWithTargetPath>
正如预期的那样,从现在开始,每次构建(Debug/Release)时,都会将相应的库复制到输出目录中。这就是它所需要的一切,希望它能对某人有所帮助。
https://stackoverflow.com/questions/51761096
复制相似问题