2009-05-20 65 views
3

我想在cc.net中自動發佈一個具有多種解決方案的項目。我使用的是msbuild,然後調用一個aspnetcompiler xml文件。問題是我的目錄包含很多解決方案,當我運行aspnetcompiler時,它給了我以下錯誤。無法使用cc.net發佈使用msbuild或aspnet_compiler

errorASPCONFIG:在應用程序級別之外使用註冊爲allowDefinition ='MachineToApplication'的節是錯誤的。此錯誤可能是由於虛擬目錄未被配置爲IIS中的應用程序造成的。我嘗試了許多論壇上給出的所有可能的解決方案。但我很困惑如何明確地告訴aspnet_compiler執行20個項目中的一個特定項目。

I am using the ccnet build to call aspnet complier 
    <msbuild> 
    <executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable> 
    <!--msbuild exe directory --> 
    <workingDirectory>C:\cc\test\code\</workingDirectory> 
    <!--your working directory --> 
    <projectFile>C:\Program Files\CruiseControl.NET\server\AspNetCompilerConfiguration.xml</projectFile> 
    <!--the configuration xml file which will hold AspNetCompiler lines--> 
    <logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger> 
    </msbuild> 

這是我AspNetCompilerConfiguration.xml文件

<Project 
    xmlns = "http://schemas.microsoft.com/developer/msbuild/2003" 
    name = "AspNetPreCompile" 
    DefaultTargets = "PrecompileWeb"> 
    <Target Name = "PrecompileWeb"> 
      <AspNetCompiler 
        VirtualPath = "test" 
        PhysicalPath = "C:\cc\test\code\" 
        TargetPath = "C:\cc\testitr\deploy\" 
        Force = "true" 
        Debug = "true" 
        Updateable = "true"/> 
    </Target> 
</Project> 

現在我想運行C:\ CC \測試\代碼\ Com.Project1.sln。但我不知道如何告訴aspnet編譯器。任何想法如何做到這一點,然後發佈這個。

回答

0

首先:你不能通過aspnet_compiler scirpt發佈網站,但你可以(Release-mode-)編譯網站,這通常是同一件事情。或者你可以按照我在這篇文章中描述的方式使用MsBuild。

我建議您將ASP.NET網站分組爲解決方案文件並構建它們。然後你有更少的參數,你可以用Visual Studio測試構建。

這裏是你如何使用您的cc.net構建文件中的一些params用於在MSBuild的-scirpt:

<msbuild> 
    <executable>C:\WINDOWS\Microsoft.NET\Framework\v3.5\MSBuild.exe</executable> 
    <!--msbuild exe directory --> 
    <workingDirectory>C:\cc\test\code\</workingDirectory> 
    <!--your working directory --> 
    <projectFile>C:\Program Files\CruiseControl.NET\server\AspNetCompilerConfiguration.xml</projectFile> 
    <!--the configuration xml file which will hold AspNetCompiler lines--> 
    <logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger> 
    <!--Build arguments. You can have multiple projects or msbuild sections in cc.net.config--> 
    <buildArgs>/p:Configuration=Debug;MyAttribute1=MyValue1;MyAttribute2=MyValue2;</buildArgs> 
    <!--targets, if not default (here PrecompileWeb) --> 
    <targets>Build;Analyze</targets> 
    </msbuild> 

然後你就可以修改你的AspNetCompilerConfiguration.xml(更好的名字在我看來會是這樣的MyWebSites .msbuild)取參數:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" name = "AspNetPreCompile" DefaultTargets = "PrecompileWeb"> 
    <!--Conditions are params from ccnet.config (or command line)--> 
    <PropertyGroup Condition="'$(MyAttribute1)' == MyValue1" > 
    <MySolution>c:\mything.sln</MySolution> 
    </PropertyGroup> 
    <PropertyGroup Condition="'$(MyAttribute1)' != MyValue1" > 
    <MySolution>c:\some_other.sln</MySolution> 
    </PropertyGroup> 

    <!--This way you could import other msbuild-scirpts to manage separate files--> 
    <!--<Import Project="Morexml.msbuild"/>--> 

    <Target Name="Build"> 
    <Exec Command="echo hello world 1!"/> 
    <MSBuild Projects="$(MySolution)" Targets="Rebuild" ContinueOnError="false" StopOnFirstFailure="false" /> 
    </Target> 
    <Target Name="Analyze"> 
    <Exec Command="echo hello world 2!"/> 
    </Target> 
    <!--default, for example, here call some tasks --> 
    <!--default is not used when targets are specified --> 
    <Target Name="PrecompileWeb"> 
    <CallTarget Targets="Build" /> 
    <CallTarget Targets="Analyze" Condition="'$(MyAttribute2)' != 'MyValue2'" /> 
    </Target> 
</Project> 

您可以使用Visual Studio或記事本配置您的解決方案.sln文件。但它應該有你的網站,像這樣:

Project("{ABCD1234-7377-472B-9ABA-BC803B73C123}") = "MyWebSite", "http://localhost/MyWebSite", "{12345678-5FD6-4177-B210-54045B098ABC}" 
    ProjectSection(WebsiteProperties) = preProject 
     Debug.AspNetCompiler.VirtualPath = "/MyWebSite" 
     Debug.AspNetCompiler.PhysicalPath = "..\..\MyWebSite\" 
     Debug.AspNetCompiler.TargetPath = "C:\MyPublishedWebsite\" 
     Debug.AspNetCompiler.Updateable = "false" 
     Debug.AspNetCompiler.ForceOverwrite = "true" 
     ... 

在那裏你可以看到屬性。 IIS不需要任何配置。 (只需檢查您發佈的Web.Config(發佈/調試等設置)或者可能使用一些msbuild-target來處理。)

希望這有助於!