2014-12-03 116 views
1

我想使用SharpDX庫,我必須自己編譯源代碼。 我可以使用Net40配置輕鬆地從他們的GitHub編譯最新的源代碼。 現在我想用編譯後的項目在我自己的項目,我發現下面這樣做: https://github.com/sharpdx/SharpDX/issues/379使用從源代碼編譯的SharpDX?

這導致我做以下步驟:

  • 下載並解壓SharpDX源代碼爲「./SharpDX」
  • 打開文件「./SharpDX/SharpDX.sln」
  • 建立在配置管理與配置Net40的SharpDX源代碼
  • 與以下內容創建文件 「./MyProject/Common.targets」:

    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
        <PropertyGroup> 
        <!-- set the location of SharpDX source code --> 
        <SharpDXLocation Condition="'$(SharpDXLocation)' == ''">..\SharpDX</SharpDXLocation> 
        <!-- the new property to include references automatically (as it was in old SharpDX.targets) --> 
        <SharpDXIncludeReferences>true</SharpDXIncludeReferences> 
        <!-- (optional) override DirectX version --> 
        <SharpDXDirectXVersion>DirectX11</SharpDXDirectXVersion> 
        <!-- disable usage of signed assemblies, as you won't have the needed private key to build them --> 
        <SharpDXNoSigned>true</SharpDXNoSigned> 
        </PropertyGroup> 
    
        <Import Project="$(SharpDXLocation)\Build\SharpDX.targets" /> 
        <Import Project="$(SharpDXLocation)\Build\SharpDX.Toolkit.targets" /> 
    </Project> 
    
  • 與以下內容創建文件 「./MyProject/SharpDXHelper.csproj」:

    <?xml version="1.0" encoding="utf-8"?> 
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="BuildTarget"> 
        <Import Project="Common.targets" /> 
        <Target Name="BuildTarget"> 
         <Message Text="Building command for SharpDXHelper" Importance="high" /> 
        </Target> 
        <Target Name="Rebuild"> 
         <Message Text="Rebuilding command for SharpDXHelper" Importance="high" /> 
        </Target> 
        <Target Name="Clean"> 
         <Message Text="Cleaning command for SharpDXHelper" Importance="high" /> 
        </Target> 
    </Project> 
    
  • 打開文件「.MyProject/SharpDXHelper.csproj」與Visual Studio。

如果我展開「參考」的「./MyProject/SharpDXHelper.csproj」的一部分,我看到一個警告圖標所需的參照,該警告是這樣的:

警告13找不到引用的組件'SharpDX'。 SharpDXHelper

我不明白我做錯了什麼,爲什麼它沒有找到正確的組件? 我意識到「Toolkit」部分已經消失,我期望那些加載失敗,但我不希望其他人失敗。

據我的理解,如果我將SharpDXHelper.csproj作爲依賴添加到其他任何項目中,我應該能夠毫無問題地使用SharpDX庫,我對這個問題正確嗎?

所產生的問題的圖像可以在這裏找到: http://puu.sh/dfmP4/c6ac1165ed.png

回答

0

據我瞭解,我應該能夠使用SharpDX庫沒有問題,如果我添加「SharpDXHelper.csproj」作爲一個依賴到任何其他項目,我對這個是否正確?

不是。

被引用的項目不被評估爲導入的項目(使用導入任務)。

  • 引用從項目A1項目B1:項目B1被認爲是可分離和編譯項目。所有由B1定義的屬性和目標在A1中不可見。
  • 將項目B1導入A1就像將項目B1內聯到A1中一樣。在B1中定義的所有屬性和目標是在A1可見(並覆蓋被列入點之前定義的所有內容)

這就是爲什麼我們使用「.targets」擴展爲引進項目,從引用的項目區分開來的理由。

儘管可能開發出這樣一個被引用的項目B1,它可以在編譯A1時被A1複製到本地,但是這需要深入瞭解.NET/C#引用的項目如何獲得交叉引用,編譯爲了做到這一點。這是可行的,但發展是一個相當大的挑戰。

我建議你堅持使用導入解決方案。

+0

我接受了您的建議,並將添加到了現有的項目文件中,並且違背了我的預期,它實際上起作用了。當然,如果沒有Toolkit API,應該可能會在某個時候更新。無可否認,我添加了導入的項目文件是爲了與NuGet(我拿出的)一起工作而設計的,所以這可能有助於解決這個問題。當我再次醒來時,我將看到_why_它與該項目文件一起工作,而不是與我所做的那個一起工作。 – ManIkWeet 2014-12-03 22:24:36