无法使用cc.net使用msbuild或aspnet_compiler发布

时间:2009-05-20 13:25:10

标签: msbuild cruisecontrol.net aspnet-compiler

我正在尝试自动发布在cc.net中有许多解决方案的项目。我正在使用msbuild,后者又调用一个aspnetcompiler xml文件。问题是我的目录包含许多解决方案,当我运行aspnetcompiler时,它会给我以下错误。

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 \ test \ code \ Com.Project1.sln。但我不知道如何告诉aspnet编译器。知道怎么做然后发布这个。

1 个答案:

答案 0 :(得分:0)

首先:你不能通过scirpt用aspnet_compiler发布网站,但你可以(发布模式)编译网站,这通常是一回事。或者您可以按照我在本文中描述的方式使用MsBuild。

我建议您将ASP.NET网站分组到解决方案文件并构建它们。然后你有更少的参数,你可以使用Visual Studio测试构建。

以下是如何在cc.net构建文件中使用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来处理它。)

希望这有帮助!