1. 程式人生 > >在Visual Studio 2010中建立多專案(解決方案)模板【二】(VS2017)

在Visual Studio 2010中建立多專案(解決方案)模板【二】(VS2017)

    我使用的環境不是VS2010而是VS2017。可能是微軟更新的原因,解決子專案引用專案名稱的問題變得簡單了。

    我們可以改造之前的子專案引用程式碼

<ProjectTemplateLink ProjectName="$safeprojectname$.Application" CopyParameters="true">
  CMSTemplate\Application\MyTemplate.vstemplate
</ProjectTemplateLink>

    這裡我們加了一個引數CopyParameters,這個引數的說明是:

If this is set to 'true', all parameters/variables in the main template will be available in the nested vstemplates with an 'ext_' prefix. For example the main template parameter $safeprojectname$ will become $ext_safeprojectname$ in the nested template - the nested template will therefore have $safeprojectname$ and $ext_safeprojectname$.

    意思是:

    如果這個值設定為"true"那麼主專案的所有引數會傳遞給子專案,使用的時候在原引數名稱前加'ext_'字首即可。例如:主專案引數$safeprojectname$在子專案中可以通過$ext_safeprojectname$引數獲取,這樣子專案中就可以同時使用$safeprojectname$和$ext_safeprojectname$兩個引數。

    也就是說我只需要將專案中剩餘的RainbowCMS替換成$ext_safeprojectname$即可。在建立專案時$ext_safeprojectname$就會替換成自己設定的【專案名稱】了,而不會向前文那樣背替換成【專案名稱.Application】。從而達到我們預期的效果。這樣也省去了GAC的設定了,比VS2010中的設定簡單了許多。