使用aspnet_compiler.exe编译.Net Web Apps

问题描述 投票:2回答:4

我在我的.Net Web应用程序的顶层有代码,我想进行单元测试,但是当我的构建服务器使用aspnet_compiler.exe编译项目时,它会创建一个完全不可用的.dll文件项目,即NUnit测试项目。

(这适用于ASP .Net Web应用程序和ASP .Net MVC应用程序。)

我在这里做错了吗?这是我调用编译器的NAnt脚本......

<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>
asp.net asp.net-mvc unit-testing nant aspnet-compiler
4个回答
3
投票

您不需要使用aspnet_compiler.exe。这只是一个实用程序应用程序,用于预编译您的aspx页面,以避免用户第一次点击页面时的启动延迟。

据我所知,在构建解决方案时,ASP.NET MVC Web应用程序中的任何非aspx / ascx代码都将正常编译为DLL。然后,您的NUnit测试项目可以使用此DLL。我认为这是你要测试的那些比特。

所以,只需使用来自NAnt的MSBuild构建项目,忘记aspnet_compiler.exe。


4
投票

我在我的.Net Web应用程序的顶层有代码,我想进行单元测试[...]

停在那儿;那就是问题所在。将该代码放入帮助程序,并在ASP.NET之外进行测试。


1
投票

难道你不能像这里一样运行,而不是在Nant中作为后期构建事件吗?

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

(其中FilePathToMyWebProject是项目文件相对于解决方案文件的路径)


0
投票

我们使用MSBuild和构建文件来编译Web应用程序并运行测试,如果你可以跳过NAnt的东西,这里是构建文件的一个相关部分(称为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>
© www.soinside.com 2019 - 2024. All rights reserved.