1 回答

TA貢獻1877條經驗 獲得超6個贊
好的,我已經分 3 個步驟解決了這個問題(在搜索了幾個小時之后)。
如上所述,.dll
如果項目是在 Windows 上構建(調試/發布),我的要求是將文件復制到輸出目錄,如果項目是.so
在 Linux 上使用 MonoDevelop 構建(調試/發布),則復制對應的庫。
我將庫復制到我的項目文件夾中的目錄(安全的某個地方),然后
Add Existing Item
在 VS 2017 中使用了--> 選擇了所需的庫文件 --> 使用Add as Link
而不是Open
(從這里找到)。我需要將它們復制到輸出目錄,而沒有從我將它們添加到項目時繼承的文件夾結構,所以我遵循了這個問題的公認答案,并能夠指示它在每次構建時復制到輸出目錄。
現在對于最后一個要求,即根據底層操作系統復制特定文件,我使用了文件中的
Condition
屬性。這是我所做的:ItemPropertyGroup
.csproj
.dll
如果基本操作系統是 Windows,我有 1 個要包含在內,如果是.so
linux,則有2 個文件要包含在內,這是我在.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>
正如預期的那樣,從現在開始,每次構建(調試/發布)時,都會將相應的庫復制到輸出目錄中。就這么多了,希望對大家有所幫助。
- 1 回答
- 0 關注
- 241 瀏覽
添加回答
舉報