无法使用msbuild或aspnet_compiler通过cc.net进行发布

3
我正在尝试自动发布一个包含多个解决方案的项目到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
首先:您不能使用aspnet_compiler脚本发布网站,但是您可以(发布模式)编译网站,这通常是相同的事情。或者您可以按照我在此帖子中描述的方式使用MsBuild。

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

以下是如何在msbuild-scirpt中使用一些参数的cc.net构建文件:

  <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或Notepad配置您的解决方案.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(Release/Debug等设置)或者使用一些MSBuild-Target来处理。)

希望这可以帮到你!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接