作者:朱金燦
來(lái)源:blog.csdn.net/clever101
一般開(kāi)發(fā)我喜歡遵循下面的規(guī)范:在項(xiàng)目解決方案文件夾下建5個(gè)文件夾:
文件夾名 |
備注 |
src |
存放解決方案的源代碼 |
thirdparty |
存放第三方庫(kù)的源代碼(無(wú)源碼的就存放頭文件) |
Doc |
存放該項(xiàng)目的相關(guān)文檔,我一般在Doc文件夾下又新建三個(gè)文件夾: Design -- 項(xiàng)目設(shè)計(jì)方面的文檔 Experience -- 項(xiàng)目經(jīng)驗(yàn)總結(jié) Other -- 項(xiàng)目其它方面的文檔,包括參考資料方面的 |
Debug |
Debug版輸出文件夾 |
Release |
Release版輸出文件夾 |
但是使用VS 2005新建一個(gè)空白解決方案,往往是新建一個(gè)解決方案文件夾再加一個(gè)sln文件,我往往要手動(dòng)建一個(gè)src文件夾,再將sln文件拷貝到該文件夾下,然后再新建thirdparty、Doc、Debug、Release,這樣重復(fù)的的工作是程序員不愿意干的。我想到了使用編程實(shí)現(xiàn)這樣的重復(fù)勞動(dòng)。開(kāi)始的想法大致就是指定一個(gè)sln文件存放文件夾,然后就自動(dòng)生成一個(gè)項(xiàng)目解決方案文件夾,里面有src、thirdparty、Doc、Debug和Release等5文件夾,其中src文件夾下有一個(gè)sln文件,Doc文件夾下有Design、Experience和Other三個(gè)文件夾。
首先需要解決的難題是sln文件是如何生成的,開(kāi)始我的想法是通過(guò)創(chuàng)建進(jìn)程,調(diào)用devenv.exe的命令行用法來(lái)新建空白解決方案文件,但是上網(wǎng)搜索了一陣,感覺(jué)VS 2005的命令行用法太過(guò)于復(fù)雜,只好另想辦法。我想到的第二種折中辦法是先用VS 2005生成一個(gè)臨時(shí)的sln文件Solution1.sln,放在我這個(gè)程序的exe文件所在目錄下,然后到時(shí)通過(guò)拷貝sln文件的辦法拷貝到用戶(hù)的指定路徑下,再重命名就行了。這樣做的一個(gè)麻煩是到時(shí)發(fā)布程序時(shí)必須帶兩個(gè)文件:exe文件和Solution1.sln。想了一下,決定使用這樣一種做法,把臨時(shí)sln文件作為資源注入到exe文件,到時(shí)運(yùn)行程序時(shí)再釋放出來(lái)。
開(kāi)始開(kāi)發(fā),新建一個(gè)基于對(duì)于框的工程SlnGen,然后使用VS 2005新建一個(gè)空白解決方案,生成一個(gè)Solution1.sln,再將Solution1.sln作為一種資源導(dǎo)入到SlnGen工程,具體操作如下:
1.在資源視圖中選擇"添加資源",然后在對(duì)話(huà)框中選中Solution1.sln,如下圖:
<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning /> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL /> <w:BalanceSingleByteDoubleByteWidth /> <w:DoNotLeaveBackslashAlone /> <w:ULTrailSpace /> <w:DoNotExpandShiftReturn /> <w:AdjustLineHeightInTable /> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:UseFELayout /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--> <!--[if gte mso 10]> <mce:style><! /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} --> <!--[endif]-->
2. 自定義一種資源 :RT_SLN
<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning /> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL /> <w:BalanceSingleByteDoubleByteWidth /> <w:DoNotLeaveBackslashAlone /> <w:ULTrailSpace /> <w:DoNotExpandShiftReturn /> <w:AdjustLineHeightInTable /> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:UseFELayout /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]-->
<!--[if gte mso 10]> <mce:style><! /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} --> <!--[endif]-->
3. 按確定后生成一個(gè)新資源,其資源 ID 為 IDR_RT_SLN1 。
開(kāi)始編碼。其實(shí)程序的邏輯很簡(jiǎn)單:就是首先新建一個(gè)解決方案文件夾,然后新建一個(gè) src 文件,再?gòu)馁Y源中釋放出 sln 文件,將其存放在 src 文件下,再新建余下的文件。
主體代碼如下:
<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning /> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL /> <w:BalanceSingleByteDoubleByteWidth /> <w:DoNotLeaveBackslashAlone /> <w:ULTrailSpace /> <w:DoNotExpandShiftReturn /> <w:AdjustLineHeightInTable /> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:UseFELayout /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]-->
<!--[if gte mso 10]> <mce:style><! /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} --> <!--[endif]-->
程序美中不足的是生成的 sln 文件在磁盤(pán)顯示的是 unrecognized version( 未識(shí)別的文件版本 ) 。不過(guò)這個(gè)絲毫不影響使用,我使用 VS 2005 打開(kāi)后再新建一個(gè)工程,馬上顯示是 VS 2005 版本的解決方案文件。
程序界面如下:
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
