我试图使我们的构建过程自动化。为此,我需要将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>


如果还有其他方法可以实现我的目标,请告诉我。

最佳答案

您最有可能的是生成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>

关于c# - 如何在NANT或csc.exe中包含对Web服务的引用?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4257397/

10-13 01:04