Using aspnet_compiler.exe to compile .Net Web Apps

I have some code in the top layer of my .Net web application that I would like to unit test, but when my build server compiles the project using aspnet_compiler.exe it creates a .dll file that is missing in all of them can be used by another project , i.e. NUnit testing project.

(This is true for ASP.Net web applications and ASP.Net MVC applications.)

Am I doing something wrong here? Here's my NAnt script that the compiler calls ...

<exec program="${asp.compiler.home}/aspnet_compiler.exe" failonerror="true">
   <arg value="-nologo"/>
   <arg value="-c"/>
   <arg value="-f"/>
   <arg value="-errorstack"/>
   <arg value="-v"/>
   <arg value="${project.name}"/>
   <arg value="-p"/>
   <arg value="${project::get-base-directory()}"/>
   <arg value="${web.deploy.dir}\${project.name}"/>
  </exec>

      

+2


source to share


4 answers


You don't need to use aspnet_compiler.exe. It's just a utility to pre-compile your aspx pages to avoid startup delays when the user first hits the page.

As I understand it, any non-aspx / ascx code in your ASP.NET MVC web application will usually be compiled into a DLL when your solution is built. This DLL can then be used by your NUnit project. I assume these are the bits you want to check.



So, just build the project with MSBuild from NAnt and forget about aspnet_compiler.exe.

+3


source


I have some code in the top layer of my .Net web application that I would like to unit test [...]



Stop right there; what a problem. Put this code in a helper and test it outside of ASP.NET.

+4


source


Can't you fire something like here and not in Nantes as a post-build event?

C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler -v / -p "$(SolutionDir)\PathToMyWebProject"

      

(where FilePathToMyWebProject is the path to your project file relative to the solution file)

+1


source


We use MSBuild with a build file to compile the web application and run tests, if you can skip the NAnt stuff, here is the relevant section from the build file (called a parameter to MSbuild.exe):

<!-- Build projects by calling the Project files generated by VS -->
  <Target Name="Build">
    <MSBuild Projects="$(ProjectFile)" />
    <MSBuild Projects="$(TestProjectFile)" />
  </Target>

  <!-- Run Unit tests -->
  <Target Name="Test" DependsOnTargets="Build">
    <CreateItem Include="ClearViewTest\Bin\Debug\ClearViewTest.exe">
      <Output TaskParameter="Include" ItemName="ClearViewTest" />
    </CreateItem>
    <NUnit Assemblies="@(ClearViewTest)" ToolPath="C:\Program Files\NUnit 2.4\bin" ContinueOnError="false" OutputXmlFile="SoultionTestResults.xml" />
  </Target>

      

0


source







All Articles