【问题标题】:How do I run NAnt build then debug when pressing F5 in VS2005在VS2005中按F5时如何运行NAnt构建然后调试
【发布时间】:2009-07-16 23:46:27
【问题描述】:

我们有许多具有 NAnt 构建文件的项目,我们可以从批处理文件中运行这些构建文件。我们朝着这个方向前进,因此我们可以将构建绑定到颠覆挂钩并自动运行测试。然而,当我们按下 F5 时,NAnt 构建的输出与 VS 生成的输出有很大不同。

我们希望能够覆盖 F5 行为以执行以下操作:

  • 运行 NAnt 脚本以构建项目和依赖项(构建文件是调试配置)。
  • 在调试模式下从目标目录启动项目,以便可以命中断点。

这是我们的一个构建文件的示例:

<?xml version='1.0' ?>
<project name='DWS.WI.Data.Common' default='all' xmlns='http://nant.sf.net/schemas/nant.xsd'>
    <property name='dbuild.dir' value='build\debug' />
    <property name='nant.settings.currentframework' value='net-2.0' />
    <property name='debug' value='true' />

    <!-- User targets -->
    <target name='all' />
    <target name='cleandeb' description='remove previous debug build files'>
        <delete dir='${dbuild.dir}' if='${directory::exists(dbuild.dir)}' />
    </target>
    <target name='init'>
        <mkdir dir='build' />
        <mkdir dir='build\debug' />
        <mkdir dir='build\release' />
    </target>
    <!-- -->
    <target name='debug' depends='cleandeb, init' description='Compiles the projects in debug mode'>
        <csc target='library' output='build\debug\${project::get-name()}.dll' rebuild='true' debug='true'>
            <sources>
                <include name='src\app\DWS.WI.Data.Common\*.cs' />
                <include name='src\app\DWS.WI.Data.Common\Properties\AssemblyInfo.cs' />
            </sources>
        </csc>
        <csc target='library' output='build\debug\DWS.WI.Data.Oracle.dll' rebuild='true' debug='true'>
            <references>
                <include name='build\debug\DWS.WI.Data.Common.dll' />
            </references>
            <sources>
                <include name='src\app\DWS.WI.Data.Oracle\*.cs' />
                <include name='src\app\DWS.WI.Data.Oracle\Properties\AssemblyInfo.cs' />
            </sources>
        </csc>
        <csc target='library' output='build\debug\DWS.WI.Data.SQL.dll' rebuild='true' debug='true'>
            <references>
                <include name='build\debug\DWS.WI.Data.Common.dll' />
                <include name='libs\Microsoft.SqlServer.ConnectionInfo.dll' />>
                <include name='libs\Microsoft.SqlServer.Smo.dll' />
                <include name='libs\Microsoft.SqlServer.SqlEnum.dll' />
            </references>
            <sources>
                <include name='src\app\DWS.WI.Data.SQL\*.cs' />
                <include name='src\app\DWS.WI.Data.SQL\Properties\AssemblyInfo.cs' />
            </sources>
        </csc>
    </target>
    <target name='test' depends='debug'>
        <csc target='library' output='build\debug\DWS.WI.Data.Fake.Test.dll' debug='true'>
            <sources>
                <include name='src\test\DWS.WI.Data.Fake.Test\*.cs' />
            </sources>
            <references>
                <include name='build\debug\DWS.WI.Data.Common.dll' />
                <include name='build\debug\DWS.WI.Data.Fake.dll' />
                <include name='tools\nunit\nunit.framework.dll' />
            </references>
        </csc>
    </target>
</project>

【问题讨论】:

  • 您是否尝试直接在 nant 构建中进行调试?为什么不让它构建东西,然后打开解决方案并手动启动调试?
  • 澄清(希望)我们想按 F5 并让 IDE 运行由 NAnt 构建编译的代码,并在调试模式下运行它,以便我们可以打断点并单步执行代码.
  • 您如何构建解决方案?使用 任务还是使用 任务?以及参数是什么?

标签: visual-studio nant


【解决方案1】:

您可能有一个用于在开发机器上手动构建东西的 VS 解决方案。为同一个二进制文件创建两个单独的项目通常是个坏主意——即使你一开始就设法使其同步,它也会立即失去同步。

如果你必须使用 nant,我建议你使用你的解决方案文件并让 Visual Studio 使用 exec 任务构建它:

<exec program="${environment::get-variable('VS80COMNTOOLS')}../IDE/devenv.com">
    <arg value="${solution_path}"/>
    <arg value="/build"/>
    <arg value="Debug|Win32"/>
</exec>

测试应该作为测试项目的构建后事件的一部分运行(同样,由 VS 本身),或者您可以在 VS 完成后在 nant 中运行它们。

以这种方式创建的二进制文件将与手动运行 Visual Studio 完全兼容(假设您在同一源代码树中打开相同的解决方案文件并选择相同的配置和平台)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-14
    • 1970-01-01
    相关资源
    最近更新 更多