如何在NANT或csc.exe中包含对Web服务的引用?

时间:2010-11-23 15:05:15

标签: c# .net asp.net nant csc

我试图自动化我们的构建过程。为此,我需要将asp.Net网站中的app_code编译为dll,以便我可以对代码运行NUnit测试。在你建议我只使用一个类库之前,我会说我同意你的观点,但是我的上级却采取了不同的看法并在我们的网站上否决了dll的使用。

我遇到的问题是app_code类引用了Web服务。在将代码编译到类库中时,如何让csc任务包含这些内容?我到目前为止的目标是:

<target name="Compile">
    <property name="nant.settings.currentframework" value="net-3.5" />
    <csc target="library" output="DocSysAppCode.dll" debug="true">
      <sources>
        <include name="D:\Inetpub\DocSys\App_Code\Common\*.cs" />
        <include name="D:\Inetpub\DocSys\App_Code\DocSys\SiteLegislation.generated.cs" />
      </sources>
      <resources>
        <include name="D:\DocSysQueue\Web References\WS_DocSys\*.*" />
        <include name="D:\DocSysQueue\app.config" />
      </resources>
    </csc>
</target>

如果还有另一种方法可以实现我的目标,请告诉我。

的Al

1 个答案:

答案 0 :(得分:1)

您最有可能生成Web服务代理类并将其编译到项目中。为此,请查看属于wsdlNantContrib任务。

您将能够执行以下操作:

<target name="generate-proxy"/>
    <wsdl path="${wsdl.url}" language="CS" namespace="svc" outfile="MyProxy.cs" verbose="true" />
</target>

然后您可以获取该任务的输出(MyProxy.cs)并将其编译到您的项目中。

<target name="Compile" depends="generate-proxy">
    <property name="nant.settings.currentframework" value="net-3.5" />
    <csc target="library" output="DocSysAppCode.dll" debug="true">
      <sources>
        <include name="MyProxy.cs" />
        <include name="D:\Inetpub\DocSys\App_Code\Common\*.cs" />
        <include name="D:\Inetpub\DocSys\App_Code\DocSys\SiteLegislation.generated.cs" />
      </sources>
    </csc>
</target>