Conditional project or library reference in Visual Studio

Conditional project or library reference in Visual?Studio

In case you were wondering why you haven’t heard from me in a while, I’ve been busy, which isn’t really of much importance unless you know me on a personal level. What is relevant is that I recently graduated with?a master in Game and Media Technology?and am now in the process of making the project which I have been working on for my thesis open source. I’m very anxious to announce it, so you’ll read a lot more about it in the near future.

The project uses two of my other open source libraries, located in separate repositories. Adding these projects to the solution and?referencing them as project references?has the advantage of easier debugging and facilitates making changes to them. However, I do not want to force anyone interested in making changes to the main project to having to download the other repositories as well. Therefore I opted to use?DLL references.?This has one major downside. Whenever I do make changes to one of the dependent libraries, I need to manually copy the newly compiled DLLs to the main project.?Wouldn’t it be easy to use?two separate solution files, one with project references, and one with DLL references?

The first problem you’ll encounter is project references aren’t stored in the?.sln?file but in the?.csproj?file, which makes sense really. Since the?.csproj?file is shared by both solutions, we’ll have to?conditionally reference either our DLLs or our projects, depending on which solution the project is opened in.?This is possible usingMSBuild, but you will need to?create a new project configuration. Setting the configuration of the project differently in one solution from the other allows you to differentiate between the two of them. The following is part of a?.csproj?file which conditionally loads a reference by checking whether the project configuration is set to ‘Debug With Project References’.

<Choose><When Condition="'$(Configuration)' == 'Debug With Project References'"><ItemGroup><ProjectReference Include="..\SomeProject\SomeProject.csproj"><Project>{6CA7AB2C-2D8D-422A-9FD4-2992BE62720A}</Project><Name>SomeProject</Name></ProjectReference></ItemGroup></When><Otherwise><ItemGroup><Reference Include="SomeProject"><HintPath>..\Libraries\SomeProject.dll</HintPath></Reference></ItemGroup></Otherwise>
</Choose>

?

You could very well stop here, but I wanted to resolve another issue as well. Unless you follow a really strict folder structure, and force everyone else who wants to open your solution to do the same,?the path used to reference the project can vary?between people. Remember we are using?separate repositories?here, and the referenced projects aren’t included in the repository of the main solution, so relative paths don’t necessarily work. It is possible to specify the paths in?an external ‘configuration’ file, and importing it into the?.csprojfile. Additionally, as a?fallback when the project can’t be found?at the given path, it is also useful to load the DLL instead. This way you can choose to load one or more, but not necessarily all references as a project reference.

The configuration file (ProjectReferences.txt):

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"><PropertyGroup Condition="$(Configuration) == 'Debug With Project References'"><SomeProject>..\SomeProject</SomeProject></PropertyGroup>
</Project>

?

Segment from the?.csproj?file:

<Import Project="..\ProjectReferences.txt" />
<Choose><When Condition="Exists($(SomeProject))"><ItemGroup><ProjectReference Include="$(SomeProject)\SomeProject.csproj"><Project>{6CA7AB2C-2D8D-422A-9FD4-2992BE62720A}</Project><Name>SomeProject</Name></ProjectReference></ItemGroup></When><Otherwise><ItemGroup><Reference Include="SomeProject"><HintPath>..\Libraries\SomeProject.dll</HintPath></Reference></ItemGroup></Otherwise>
</Choose>

?

Notice the project configuration check now occurs in the configuration file. The ‘$(SomeProject)’?property?is only set when using the ‘Debug With Project References’?configuration, thus in all other scenarios the DLL will be loaded instead since the ‘Exists()‘ check will fail.

One last issue remains. We still need to?manually copy the latest compiled DLLs?to the ‘Libraries’?folder when changes were made for the solution which uses them to work as expected. We can exploit the fact that we now have the relevant project paths available in the configuration file. Using a post build event you can call a script which parses the XML data, and copies the DLLs to the correct location. This script should be called conditionally, only for the solution which includes the project references, and ideally also only for a?Releasebuild. I used?a small Ruby script?which offers a lot more flexibility than a Batch script.

The post build event:

if "$(SolutionName)" == "SomeSolution With Project References" if "$(ConfigurationName)" == "Release" ruby $(SolutionDir)UpdateLibraryDlls.rb $(SolutionDir)

?

轉載于:https://www.cnblogs.com/zhahost/p/4796343.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/458904.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/458904.shtml
英文地址,請注明出處:http://en.pswp.cn/news/458904.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

linux 雙mipi攝像頭,VS-RK3399 在linux系統下面調試Mipi camera接口介紹

該樓層疑似違規已被系統折疊 隱藏此樓查看此樓debian系統目前支持Usb camera是沒有問題&#xff0c;走UVC功能接口。那么mipi 接口camera和并口接口的camera&#xff0c;在Debian系統怎么設置呢&#xff0c;其實原理一樣&#xff0c;也走uvc接口封裝函數.下面深圳視壯給大家簡單…

HTTP必知必會

2019獨角獸企業重金招聘Python工程師標準>>> HTTP消息HTTP請求消息HTTP響應消息消息首行請求行響應行消息頭部請求頭請求頭消息正文請求正文響應正文Web服務器把接收到的HTTP請求消息封裝成request對象&#xff0c;作為service的參數傳入service函數&#xff0c;ser…

float數據在計算機內存中的存儲方法

*************************************************** 更多精彩&#xff0c;歡迎進入&#xff1a;http://shop115376623.taobao.com *************************************************** 浮點型變量在計算機內存中占用4字節&#xff08;Byte&#xff09;,即32-bit。遵循IEEE…

Geometric Shapes - POJ 3449(多邊形相交)

題目大意&#xff1a;給一些幾何圖形的編號&#xff0c;求出來這些圖形都和那些相交。分析&#xff1a;輸入的正方形對角線上的兩個點&#xff0c;所以需要求出來另外兩個點&#xff0c;公式是&#xff1a;x2:(x1x3y3-y1)/2; y2:(y1y3x1-x3)/2;x4:(x1x3-y3y1)/2; y4:(y1y3-x1x3…

更新10_linux,時隔十年,QQ更新了Linux版本

昨天1024程序員節&#xff0c;QQ悄悄地更新了QQ for Linux&#xff0c;也許是給各位一個驚喜吧。官網及其的簡陋。和一個Word文檔似的。十年一更&#xff0c;有網友稱&#xff0c;瞬間回到QQ2006&#xff0c;確實界面功能有些落后&#xff0c;相信QQ可以跟上潮流的&#xff0c;…

[滲透測試]掃目錄,Sqlmap利用均超時,利用dirb掃描

今天碰到一個網友傳來的Webshell地址&#xff0c;問我對方如何取得webshell。 網站為阿里云服務器&#xff0c;存在明顯的注入漏洞&#xff0c;但是任何語句都會令網頁報錯&#xff0c;sqlmap一直超時&#xff0c;御劍掃描目錄1個線程也會導致被屏蔽IP。 經一學長提點&#xff…

x = x+1,x+=1,x++那個的執行效率高

*************************************************** 更多精彩&#xff0c;歡迎進入&#xff1a;http://shop115376623.taobao.com *************************************************** x x1的效率最低 1&#xff09;讀取右邊x的地址 2&#xff09;執行x13&#xff09;讀…

修正線性單元(Rectified linear unit,ReLU)

修正線性單元&#xff08;Rectified linear unit&#xff0c;ReLU&#xff09; Rectified linear unit 在神經網絡中&#xff0c;常用到的激活函數有sigmoid函數f(x)11exp(?x)、雙曲正切函數f(x)tanh(x)&#xff0c;今天要說的是另外一種activation function&#xff0c;recti…

C語言綜合期末作業,內蒙古農業大學2010年期末c語言綜合作業.doc

內蒙古農業大學2010年期末c語言綜合作業綜合練習作業#includeint main(void){int choice,i;void shuai();void ge();void wang();void bing();for(i1;i<5;i){printf("[1]統計字符個數\n");printf("[2]判斷素數\n");printf("[3]求斐波那契數列\n&qu…

鏈表創建、逆置、刪除詳解

*************************************************** 更多精彩&#xff0c;歡迎進入&#xff1a;http://shop115376623.taobao.com *************************************************** 對鏈表的理解&#xff1a;http://www.nowamagic.net/librarys/veda/detail/2220 #inc…

python與shell的3種交互方式介紹

【目錄】 1.os.system(cmd) 2.os.popen(cmd) 3.利用subprocess模塊 4.subprocessor模塊進階 【概述】 考慮這樣一個問題&#xff0c;有hello.py腳本&#xff0c;輸出”hello, world!”&#xff1b;有testinput.py腳本&#xff0c;等待用戶輸入&#xff0c;然后打印用戶輸入的數…

C語言里if語句變量作為判斷條件,C語言教學(九-上)if else判斷語句

原標題&#xff1a;C語言教學(九-上)if else判斷語句今天講if else判斷語句&#xff0c;簡單理解就是進行條件判斷&#xff0c;如果條件達到則執行if 里或else里的語句。先來看if。if的寫法和for差不多,就是不用括號里的兩個分號&#xff0c;if (條件) { }&#xff0c;if加括號…

const修飾指針和引用的用法【轉貼】

*************************************************** 更多精彩&#xff0c;歡迎進入&#xff1a;http://shop115376623.taobao.com *************************************************** const修飾的指針會額外的占內存嗎&#xff1f; 仍然是4&#xff0c;不會占額外的…

調整linux系統時區

cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 好吧&#xff0c;使用tzselect又靠譜些&#xff0c;使用前把/etc/localtime刪除了。 執行上前那個告訴我文件重新了&#xff0c;所以就沒有搞了轉載于:https://www.cnblogs.com/hark0623/p/4807426.html

stm32c語言設計以及注釋,13個基于STM32的經典項目設計實例,全套資料~-嵌入式系統-與非網...

STM32單片機現已火遍大江南北&#xff0c;各種教程資料也是遍布各大網站論壇&#xff0c;可謂一抓一大把&#xff0c;但大部分都差不多。今天總結了幾篇電路城上關于STM32 的制作&#xff0c;不能說每篇都是經典&#xff0c;但都是在其他地方找不到的&#xff0c;很有學習參考意…

memcpy,strcpy,strncpy

*************************************************** 更多精彩&#xff0c;歡迎進入&#xff1a;http://shop115376623.taobao.com *************************************************** memcpy c和c使用的內存拷貝函數.從源src所指的內存地址的起始位置開始拷貝n個字節…

二維數組聯通子數組和最大

題目要求&#xff1a; 返回一個二維整數數組中最大聯通子數組的和。輸入一個二維整形數組&#xff0c;數組里有正數也有負數。文件輸出。思路:和之前的動態規劃相識&#xff0c;把二維數組轉換為一維數組&#xff0c;先求每一個列的子數組和最大&#xff0c;最后在用正數就加&a…

c語言如何給變量加鎖,C語言互斥鎖-條件變量實現公共緩存區數據讀寫

#include char buffer[128];int has_data0;pthread_mutex_t mutex;pthread_cond_t cond;pthread_cond_t cond2;void read_buf(void){do{pthread_mutex_lock(&mutex);//鎖定互斥鎖if(has_data0){/*阻塞線程,等待另外一個線程發送信號&#xff0c;同時為公共數據區解鎖*/pthr…

view-activity跟控件在onkey事件上的傳遞關系

android 中Activity跟View對于鍵盤的監聽&#xff0c;主要有以下幾個方法 //按鍵按下 public boolean onKeyDown(int keyCode, KeyEvent event) {} //按鍵彈起 public boolean onKeyUp(int keyCode, KeyEvent event) {} //常按 public boolean onKeyLongPress(int keyCode, Ke…

PMP考試的過與不過

*************************************************** 更多精彩&#xff0c;歡迎進入&#xff1a;http://shop115376623.taobao.com *************************************************** 我在一年多時間里參加了三次PMP考試&#xff0c;前兩次都失敗&#xff0c;直到第三次才…