Visual Studio重写网站的解决方案配置

时间:2016-12-30 10:37:09

标签: visual-studio msbuild web

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

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

网站尚未建成。

好的,我可以手动编辑解决方案文件并更改/添加Dev.XXXX,Test.XXX等相关设置,一切运行正常,直到您在Visual Studio中打开解决方案并保存它。 Visual Studio会解除您所有的更改,您再次面临同样的问题。

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

1 个答案:

答案 0 :(得分:0)

您可以使用不同的自定义AspNetCompiler MSBuild任务构建Web站点项目。像这样:

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