【问题标题】:Unable to publish using msbuild or aspnet_compiler using cc.net无法使用 msbuild 或使用 cc.net 的 aspnet_compiler 发布
【发布时间】:2009-05-20 13:25:10
【问题描述】:

我正在尝试自动发布在 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 编译器。知道如何执行此操作然后发布此内容。

【问题讨论】:

    标签: msbuild cruisecontrol.net aspnet-compiler


    【解决方案1】:

    首先:您不能使用 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 来处理。)

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-23
      • 2018-02-03
      相关资源
      最近更新 更多