我的C#項目引用了我擁有源代碼的第三方DLL。我可以以某種方式告訴Visual Studio該源代碼的位置,例如,當我按下F12來打開DLL中某個方法的定義時,它會打開源代碼,而不是打開「類[來自元數據]「存根代碼?Visual Studio - 將源代碼附加到引用
回答
可以這樣做的一種方法是在解決方案中創建另一個項目,將DLL源代碼放在那裏,然後從主項目中添加依賴項作爲項目引用而不是程序集引用。這應該讓你在調試時瀏覽源代碼/步驟,等等。
可能有一個更簡單的方法來做到這一點,但目前我還沒有意識到。
看起來答案接近this MSDN documentation page的底部。
調試器查找源文件在以下位置:
1. Files that are open in the IDE of the Visual Studio instance that launched the debugger. 2. Files in the solution that is open in the VS instance. 3. Directories that are specified in the "Common Properties"/"Debug Source Files" page in the properties of the solution. 4. The source information of the .pdb of the module. This can be the location of the source file when the module was built, or it can be a command to a source server.
將目錄添加到該解決方案的調試源文件頁(第3步以上):
您可以指定一個網絡或本地目錄來搜索源文件 。
1. Select the solution in Solution Explorer and then choose "Properties" from the shortcut menu (i.e. right-click context menu). 2. Under the "Common Properties" node, choose "Debug Source Files". 3. Click the folder icon. Editable text appears in the "Directories containing source code" list. 4. Add the path that you want to search.
請注意,只搜索指定的目錄。您必須爲要搜索的任何子目錄添加 條目。
所以,如果你只想調試一個特定的文件一次而不會混淆你的解決方案,只需在Visual Studio IDE中打開該文件;如果您需要從該文件導入其他文件,則可能還需要在Visual Studio中打開其他文件。
如果你經常發現自己需要調試源文件的解決方案之外,則您可以:
- 源文件添加到現有的項目之一,在解決方案,或創建一個新項目容納源文件的解決方案。這會混亂你的解決方案/項目,但由於它將被檢入到源代碼控制中,所有團隊成員將自動能夠調試到源文件中。
- 將包含源代碼的目錄添加到解決方案的「調試源文件」中。由於此更改未檢入源代碼管理,因此每個想要調試源文件的團隊成員都需要執行此操作並添加其本地路徑。另外,如果您在另一臺機器上獲得解決方案代碼,則需要記住再次執行此步驟。
不幸的是,這隻有在*調試*使用程序集的正在運行的程序時纔有效。 Joe尋找的是一種在IDE中執行代碼導航(例如查找定義,用法等)而不運行代碼的方式。如果ReSharper已經解決了這個問題,那就太好了。我希望更新版本的Visual Studio也有內置的功能,但我找不到它。有誰知道? – Minyu 2015-01-17 19:48:20
Resharper是我能找到的唯一方法。我對Visual Studio 2015 Enterprise(如此昂貴的一款軟件)不支持這樣一個簡單的功能感到驚訝,這個功能恰好是「企業」級IDE的事後考慮,比如Eclipse,一個免費的開源軟件軟件。 – netlander 2017-07-20 12:30:03
- 1. 如何將源代碼附加到Visual Studio中的引用程序集
- 2. 將Visual Studio引用添加到源代碼管理下的產品
- 3. 將源代碼附加到Jprofiler
- 4. 將源代碼附加到VisualVM?
- 5. 將自定義軟件包源添加到Visual Studio代碼
- 6. 將第三方庫添加到Visual Studio源代碼控制中
- 7. Visual Studio - 源代碼控制
- 8. Visual Studio mscorlib類源代碼
- 9. visual studio源代碼步進
- 10. 將DLL引用添加到Visual Studio宏
- 11. Visual Studio - 附加到進程
- 12. Visual Studio附加到流程
- 13. 從Visual Studio啓動並附加到NW.JS程序代碼
- 14. Visual Studio附加到進程並查看break上的代碼?
- 15. 使用Visual Studio管理源代碼管理中的引用
- 16. Visual Studio沒有源代碼可用
- 17. Visual Studio:用源代碼調試Chrome?
- 18. Visual Studio將調試器附加到Windows服務 - 附加灰顯
- 19. 未找到源代碼:添加源代碼附件查看源代碼
- 20. 的Visual Studio 2015年TFS文件添加到源代碼控制
- 21. 在Visual Studio中引用DLL代碼
- 22. 如何將Visual Studio 2013項目導出到源代碼中
- 23. OpsHub僅將源代碼從TFS 2010遷移到Visual Studio Online
- 24. 使用Visual Studio將代碼添加到TFS
- 25. Visual Studio將代碼標記爲代碼
- 26. 如何將源碼附加到android.jar中
- 27. 將moc_objectcontroller.cpp添加到Visual Studio源代碼樹時出現QtPropertyBrowser編譯器錯誤
- 28. 如何在Mac OS X上將其他NuGet包源添加到Visual Studio代碼?
- 29. 如何將源代碼添加到Visual Studio Express 2012中的.dll文件?
- 30. 將Visual Studio 2015項目添加到源代碼控制的問題
看到重複的問題:http://stackoverflow.com/questions/5368423/how-to-attach-sources-to-referenced-assembly-in-visual-studio – 2013-02-26 20:01:11