views:

1986

answers:

2

I am trying to automate publishing a project having many solutions in cc.net. I am using msbuild which in turn calls a aspnetcompiler xml file. Problem is my directory contains many solutions and when I run aspnetcompiler it gives me the following error.

errorASPCONFIG: It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS

I have tried all possible solutions given at many forums. But I am confused how to explicitly tell aspnet_compiler to execute a particular project out of 20 projects.

  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>

this is my AspNetCompilerConfiguration.xml file

<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>

Now I want to run C:\cc\test\code\Com.Project1.sln. but i dont know how to tell aspnet compiler. Any idea how to do this and then publish this.

A: 

First of all: you can't publish website by scirpt with aspnet_compiler but you can (Release-mode-)compile website which is generally the same thing. Or you can use MsBuild by the way I describe in this post.

I recommend you to group your ASP.NET Websites to solution files and build them. Then you have less params and you can test the build with Visual Studio.

Here is how you can use some params in your cc.net build file for 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>

Then you can modify your AspNetCompilerConfiguration.xml (better name in my opinion would be something like MyWebSites.msbuild) to take params:

<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>

You can configure your solution .sln-file with Visual Studio or Notepad. However it should have your websites, something like this:

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"
     ...

There you can see the properties. There is no need for IIS any configuration. (Just check your released Web.Config (Release/Debug, etc. settings) or maybe use some msbuild-Target to handle that.)

Hope this helps!

Tuomas Hietanen
A: 

We need to do something similar, we're publishing from a build server to another server. Which property or properties should we configure in order to articulate the correct build outcome?

Michael