做新项目,当时参考NopCommerce的结构,后台Nop.Admin是一个独立的Area Web Site,但部署的时候发现,使用一键发布,Admin Area会丢失。
研究了下NopCommerce的做法,使用MSBuild组织文件结构,关键的地方在下面:
<!--Now lets publish Nop.Admin--> <MSBuild Projects="$(RootFolder)PresentationNop.WebAdministrationNop.Admin.csproj" Targets="ResolveReferences;_CopyWebApplication" Properties="WebProjectOutputDir=$(DeployFolder)$(DeployPrefix)Administration; OutDir=$(DeployFolder)$(DeployPrefix)Administrationin;Configuration=$(Configuration)" /> <!--Now lets move the Nop.Admin/bin/ to the root bin/--> <CreateItem Include="$(DeployFolder)$(DeployPrefix)Administrationin*.dll"> <Output TaskParameter="Include" ItemName="CompileOutput" /> </CreateItem> <Copy SourceFiles="@(CompileOutput)" DestinationFolder="$(DeployFolder)$(DeployPrefix)in" /> <!--Lets delete the bin in Nop.Admin--> <RemoveDir Directories="$(DeployFolder)$(DeployPrefix)Administrationin" /> <!--Lets delete the packages.config files--> <Delete Files="$(DeployFolder)$(DeployPrefix)Administrationpackages.config; $(DeployFolder)$(DeployPrefix)packages.config"/>
然后发布的时候可以使用Web.Release.config替换Web.config
<!--Transform support--> <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)MicrosoftVisualStudiov$(VisualStudioVersion)WebMicrosoft.Web.Publishing.Tasks.dll"/> <!--Transform root web.config file--> <TransformXml Condition="Exists('$(WebFolder)Web.$(Configuration).config')" Source="$(WebFolder)Web.config" Transform="$(WebFolder)Web.$(Configuration).config" Destination="$(DeployFolder)$(DeployPrefix)Web.config" />
使用Settings.Release.txt替换Settings.txt
<!--Lets Copy App_DataSettings.Release.txt To App_DataSettings.txt --> <Copy Condition="Exists('$(WebFolder)App_DataSettings.$(Configuration).txt')" SourceFiles="$(WebFolder)App_DataSettings.$(Configuration).txt" DestinationFiles="$(DeployFolder)$(DeployPrefix)App_DataSettings.txt" SkipUnchangedFiles="true" OverwriteReadOnlyFiles="true" /> <!--Lets delete the Settings.Release.txt file--> <Delete Condition="Exists('$(DeployFolder)$(DeployPrefix)App_DataSettings.$(Configuration).txt')" Files="$(DeployFolder)$(DeployPrefix)App_DataSettings.$(Configuration).txt"/>
MSBuild配置文件,可下载参考。
装了Win8+VS2013后,生成时会提示:
error MSB4019: 未找到导入的项目“C:Program Files (x86)MSBuildMicrosoftVisualStudiov11.0WebApplicationsMicrosoft.WebApplication.targets”。请确认 <Import> 声明中的路径正确,且磁盘上存在该文件。
解决方法:
在命令行使用"C:Program Files (x86)MSBuild12.0BinMSBuild.exe"替换”%windir%Microsoft.NETFrameworkv4.0.30319MSBuild.exe“
或者从别的开发机上复制一份WebApplications
参考文章:
http://blogs.msdn.com/b/visualstudio/archive/2013/07/24/msbuild-is-now-part-of-visual-studio.aspx
MSBuild学习资料: