【问题标题】:Going from <solution> to <exec program=msbuild> in NAnt在 NAnt 中从 <solution> 到 <exec program=msbuild>
【发布时间】:2009-08-18 00:32:51
【问题描述】:

我已将我的应用程序从 .NET 1.1 转换为 .NET 3.5,不幸的是 NAnt 的标签不支持 .NET 3.5。所以我试图使用标签直接启动 msbuild。

这是 .NET 1.1 的内容:

<solution solutionfile="MyApp.sln" 
        configuration="ServerDebug" outputdir="MyApp\bin\ServerDebug">

             <assemblyfolders>
                   <include name="Dependencies\Libs\bin\ServerDebug"/>
             </assemblyfolders>
</solution>

我把它转换成

<exec program="msbuild">
    <arg value="MyApp.sln /p:Configuration=ServerDebug;OutDir=bin\ServerDebug\" />
</exec>

所以一切正常,除了我不知道如何复制真正方便的标签,这给了编译器一个关于在哪里寻找依赖项的提示。

我将什么传递给 msbuild 以复制功能?

【问题讨论】:

    标签: .net msbuild nant projects-and-solutions


    【解决方案1】:

    我认为可以通过以下两个选项之一来完成。通过使用 AdditionalLibPathsAssemblySearchPaths,它们在 on MSDN 中进行了描述。

    类似于以下内容:

    <exec program="msbuild.exe">
        <arg line="/p:Configuration=ServerDebug"/>
        <arg line="/p:OutDir=bin\ServerDebug\" />
        <arg line="/p:AssemblySearchPaths=Dependencies\Libs\bin\ServerDebug" />
        <arg line="MyApp.sln" />
    </exec>
    

    【讨论】:

      【解决方案2】:

      不管怎样,通过将以下内容添加到 NAnt.exe.config,我能够让 NAnt 0.86 与 .NET 3.5 一起使用。这样做之后,我的构建文件中 project 标记内的这一位就是我所需要的。

      <property name="nant.settings.currentframework" value="net-3.5" />
      

      添加到 NAnt.exe.config:

      <framework 
          name="net-3.5"
          family="net"
          version="2.0"
          description="Microsoft .NET Framework 3.5"
          sdkdirectory="${path::combine(sdkInstallRoot, 'bin')}"
          frameworkdirectory="${path::combine(installRoot, 'v3.5')}"
          frameworkassemblydirectory="${path::combine(installRoot, 'v2.0.50727')}"
          clrversion="2.0.50727"
          >
          <runtime>
              <probing-paths>
                  <directory name="lib/net/2.0" />
                  <directory name="lib/net/neutral" />
                  <directory name="lib/common/2.0" />
                  <directory name="lib/common/neutral" />
              </probing-paths>
              <modes>
                  <strict>
                      <environment>
                          <variable name="COMPLUS_VERSION" value="v2.0.50727" />
                      </environment>
                  </strict>
              </modes>
          </runtime>
          <reference-assemblies basedir="${path::combine(installRoot, 'v2.0.50727')}">
              <include name="Accessibility.dll" />
              <include name="mscorlib.dll" />
              <include name="Microsoft.Build.Utilities.dll" />
              <include name="Microsoft.Vsa.dll" />
              <include name="Microsoft.VisualBasic.dll" />
              <include name="Microsoft.VisualBasic.Compatibility.dll" />
              <include name="Microsoft.VisualBasic.Compatibility.Data.dll" />
              <include name="System.Configuration.dll" />
              <include name="System.Configuration.Install.dll" />
              <include name="System.Data.dll" />
              <include name="System.Data.OracleClient.dll" />
              <include name="System.Data.SqlXml.dll" />
              <include name="System.Deployment.dll" />
              <include name="System.Design.dll" />
              <include name="System.DirectoryServices.dll" />
              <include name="System.dll" />
              <include name="System.Drawing.Design.dll" />
              <include name="System.Drawing.dll" />
              <include name="System.EnterpriseServices.dll" />
              <include name="System.Management.dll" />
              <include name="System.Messaging.dll" />
              <include name="System.Runtime.Remoting.dll" />
              <include name="System.Runtime.Serialization.Formatters.Soap.dll" />
              <include name="System.Security.dll" />
              <include name="System.ServiceProcess.dll" />
              <include name="System.Transactions.dll" />
              <include name="System.Web.dll" />
              <include name="System.Web.Mobile.dll" />
              <include name="System.Web.RegularExpressions.dll" />
              <include name="System.Web.Services.dll" />
              <include name="System.Windows.Forms.dll" />
              <include name="System.Xml.dll" />
          </reference-assemblies>
          <reference-assemblies basedir="${environment::get-folder-path('ProgramFiles')}/Reference Assemblies/Microsoft/Framework/v3.5">
              <include name="Microsoft.Build.Engine.dll" />
              <include name="Microsoft.Build.Framework.dll" />
              <include name="System.AddIn.Contract.dll" />
              <include name="System.AddIn.dll" />
              <include name="System.Core.dll" />
              <include name="System.Data.DataSetExtensions.dll" />
              <include name="System.Data.Linq.dll" />
              <include name="System.DirectoryServices.AccountManagement.dll" />
              <include name="System.Management.Instrumentation.dll" />
              <include name="System.Net.dll" />
              <include name="System.ServiceModel.Web.dll" />
              <include name="System.Web.Extensions.Design.dll" />
              <include name="System.Web.Extensions.dll" />
              <include name="System.Windows.Presentation.dll" />
              <include name="System.WorkflowServices.dll" />
              <include name="System.Xml.Linq.dll" />
          </reference-assemblies>
          <reference-assemblies basedir="${environment::get-folder-path('ProgramFiles')}/Reference Assemblies/Microsoft/Framework/v3.0">
              <include name="System.IdentityModel.dll" />
              <include name="System.IdentityModel.Selectors.dll" />
              <include name="System.IO.Log.dll" />
              <include name="System.Printing.dll" />
              <include name="System.Runtime.Serialization.dll" />
              <include name="System.ServiceModel.dll" />
              <include name="System.Speech.dll" />
              <include name="System.Workflow.Activities.dll" />
              <include name="System.Workflow.ComponentModel.dll" />
              <include name="System.Workflow.Runtime.dll" />
              <include name="WindowsBase.dll" />
          </reference-assemblies>
          <task-assemblies>
              <!-- include MS.NET version-neutral assemblies -->
              <include name="extensions/net/neutral/**/*.dll" />
              <!-- include MS.NET 2.0 specific assemblies -->
              <include name="extensions/net/2.0/**/*.dll" />
              <!-- include MS.NET specific task assembly -->
              <include name="NAnt.MSNetTasks.dll" />
              <!-- include MS.NET specific test assembly -->
              <include name="NAnt.MSNet.Tests.dll" />
              <!-- include .NET 2.0 specific assemblies -->
              <include name="extensions/common/2.0/**/*.dll" />
          </task-assemblies>
          <tool-paths>
              <directory name="${path::combine(sdkInstallRoot, 'bin')}" />
              <directory name="${path::combine(installRoot, 'v3.5')}" />
              <directory name="${path::combine(installRoot, 'v2.0.50727')}" />
          </tool-paths>
          <project>
              <readregistry
                  property="installRoot"
                  key="SOFTWARE\Microsoft\.NETFramework\InstallRoot"
                  hive="LocalMachine" />
              <readregistry
                  property="sdkInstallRoot"
                  key="SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.1\WinSDKNetFxTools\InstallationFolder"
                  hive="LocalMachine"
                  failonerror="false" />
              <property name="frameworkDirectoryV35" value="${path::combine(installRoot, 'v3.5')}" />
              <fail if="${not(directory::exists(frameworkDirectoryV35))}">The Framework directory for .NET 3.5 does not exist.</fail>
              <property name="referenceV35" value="${environment::get-folder-path('ProgramFiles')}/Reference Assemblies/Microsoft/Framework/v3.5" />
              <fail if="${not(directory::exists(referenceV35))}">The Reference Assemblies directory for .NET 3.5 does not exist.</fail>
          </project>
          <tasks>
              <task name="csc">
                  <attribute name="exename">${path::combine(frameworkDirectoryV35,'csc.exe')}</attribute>
                  <attribute name="supportsnowarnlist">true</attribute>
                  <attribute name="supportswarnaserrorlist">true</attribute>
                  <attribute name="supportskeycontainer">true</attribute>
                  <attribute name="supportskeyfile">true</attribute>
                  <attribute name="supportsdelaysign">true</attribute>
                  <attribute name="supportsplatform">true</attribute>
                  <attribute name="supportslangversion">true</attribute>
              </task>
              <task name="vbc">
                  <attribute name="exename">${path::combine(frameworkDirectoryV35,'vbc.exe')}</attribute>
                  <attribute name="supportsdocgeneration">true</attribute>
                  <attribute name="supportsnostdlib">true</attribute>
                  <attribute name="supportsnowarnlist">true</attribute>
                  <attribute name="supportskeycontainer">true</attribute>
                  <attribute name="supportskeyfile">true</attribute>
                  <attribute name="supportsdelaysign">true</attribute>
                  <attribute name="supportsplatform">true</attribute>
                  <attribute name="supportswarnaserrorlist">true</attribute>
              </task>
              <task name="jsc">
                  <attribute name="supportsplatform">true</attribute>
              </task>
              <task name="vjc">
                  <attribute name="supportsnowarnlist">true</attribute>
                  <attribute name="supportskeycontainer">true</attribute>
                  <attribute name="supportskeyfile">true</attribute>
                  <attribute name="supportsdelaysign">true</attribute>
              </task>
              <task name="resgen">
                  <attribute name="supportsassemblyreferences">true</attribute>
                  <attribute name="supportsexternalfilereferences">true</attribute>
              </task>
              <task name="al">
                  <attribute name="exename">${path::combine(sdkInstallRoot, 'bin/al.exe')}</attribute>
              </task>
              <task name="delay-sign">
                  <attribute name="exename">sn</attribute>
              </task>
              <task name="license">
                  <attribute name="exename">lc</attribute>
                  <attribute name="supportsassemblyreferences">true</attribute>
              </task>
          </tasks>
      </framework>
      

      【讨论】:

        【解决方案3】:

        我用 Nant 和 CC.Net 做配置管理已经有一段时间了。根据我的经验,我不建议使用 Nant MSBuild 任务,而是最简单的方法是创建任务,创建任务执行的 .bat 文件。推荐使用命令行 Visual Studio 的原因有很多,其中一个原因是 MSI 包不容易使用 Nant 构建,即使您使用 contrib。这种方式更容易,也更快。

        ---------2.0 ------------- "C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv" C:\YourProject\YourSoultion.sln /Rebuild release

        ----------3.5-------------- "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv" C:\YourProject\YourSoultion.sln /Rebuild release

        【讨论】:

        • 在批处理文件中调用MSBuild不是更好吗?
        • Devenv,确实引用了 MSBuild 来构建 sln 文件。仅调用 MSbuild 与 Devenv 之间存在一些细微差别。我们的开发团队在 VS 2008 上,调用 Devenv 命令行基本上会产生与我们的开发团队将产生的完全相同的输出。这就是我选择它而不是仅仅调用 MSbuild 的原因,这样如果出现问题,我们知道我们正在比较苹果和苹果,并且至少可以消除构建环境。尽管与仅调用 Msbuild 相比,Devenv 会慢一些,但通常不会慢很多。
        • Devenv 需要在构建服务器上安装 Visual Studio。出于许可原因(和简单性),许多构建服务器只安装了框架,这就是构建项目所需的全部内容。假设您避免安装和 Web 部署项目,无论如何都应该避免这种情况,并使用不依赖于 Visual Studio 来构建的替代方案。
        猜你喜欢
        • 1970-01-01
        • 2010-11-06
        • 2010-09-05
        • 2011-06-01
        • 2012-06-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多