2016-12-30 116 views
0

我有一个网站项目解决方案。有三种自定义解决方案配置:Dev,Test,Prod。但是,网站项目没有.csproj文件,并且没有办法(或者我无法找到它)使用Web站点项目的配置。 我使用的MSBuild构建解决方案:针对网站的Visual Studio重写解决方案配置

MSBuild.exe MySolution.sln /m /p:Platform=x86;TargetFrameworkVersion=v4.6.2;OutputPath=bin;Configuration=Dev /ToolsVersion:14.0 

由于.sln文件没有关于网站项目我的开发配置的任何信息,只有调试和发布“节”:

Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "Web", "Web\", "{1F81A0DB-6FF4-4F89-B988-6D327797C4FD}" 
ProjectSection(WebsiteProperties) = preProject 
    TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.6.2" 
    ProjectReferences = "{12A625AA-8B5A-4336-AA4A-3630AAB3A27D}|MyLib.dll;" 
    Debug.AspNetCompiler.VirtualPath = "/localhost_54141" 
    Debug.AspNetCompiler.PhysicalPath = "Web\" 
    Debug.AspNetCompiler.TargetPath = "PrecompiledWeb\localhost_54141\" 
    Debug.AspNetCompiler.Updateable = "true" 
    Debug.AspNetCompiler.ForceOverwrite = "true" 
    Debug.AspNetCompiler.FixedNames = "false" 
    Debug.AspNetCompiler.Debug = "True" 
    Release.AspNetCompiler.VirtualPath = "/localhost_54141" 
    Release.AspNetCompiler.PhysicalPath = "Web\" 
    Release.AspNetCompiler.TargetPath = "PrecompiledWeb\localhost_54141\" 
    Release.AspNetCompiler.Updateable = "true" 
    Release.AspNetCompiler.ForceOverwrite = "true" 
    Release.AspNetCompiler.FixedNames = "false" 
    Release.AspNetCompiler.Debug = "False" 
    VWDPort = "54141" 
    SlnRelativePath = "Web\" 
    StartServerOnDebug = "false" 
EndProjectSection 

EndProject

并且网站没有被建立。

OK,我可以手动编辑解决方案文件和变更/添加Dev.XXXX,Test.XXX等相关设置,一切运作良好,直到你在Visual Studio开放的解决方案,并将其保存。 Visual Studio将完成所有更改并再次面临同样的问题。

作为一种变通方法,我可以创建.sln文件的副本,并手动将其与原来的解决方案同步。有人有更好的主意吗?

回答

0

您可以通过使用不同的自定义AspNetCompiler MSBuild任务建立网站项目。像这样:

dev.msbuild

<Project xmlns = "http://schemas.microsoft.com/developer/msbuild/2003"> 
     <Target Name = "PrecompileWeb"> 
       <AspNetCompiler 
         VirtualPath = "/dev" 
         PhysicalPath = "D:\Project\WebSite1\" 
         TargetPath = "PrecompiledWeb\dev\" 
         Force = "true"   
         Debug = "False" 
         Updateable = "true"/> 
     </Target> 
</Project> 

Test.msbuild

<Project xmlns = "http://schemas.microsoft.com/developer/msbuild/2003"> 
      <Target Name = "PrecompileWeb"> 
        <AspNetCompiler 
          VirtualPath = "/test" 
          PhysicalPath = "D:\Project\WebSite1\" 
          TargetPath = "PrecompiledWeb\test\" 
          Force = "true"   
          Debug = "False" 
          Updateable = "true"/> 
      </Target> 
    </Project> 

构建命令是这样的:

MSBuild.exe dev.msbuild /m /p:TargetFrameworkVersion=v4.6.2;OutputPath=bin /ToolsVersion:14.0