Going from to in

2019-02-15 12:49发布

问题:

I've converted my app from .NET 1.1 to .NET 3.5 and unfortunately NAnt's tag does not support .NET 3.5. So I am trying to use the tag to kick off msbuild directly.

Here is what I have for .NET 1.1:

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

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

I converted it to

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

So everything is working fine, except that I can't figure out how to replicate the really convinient tag, which gives the compiler a hint as to where to look for dependecies.

What do i pass to msbuild to replicate the functionality?

回答1:

I think it can be done with one of two options. Either by using AdditionalLibPaths or AssemblySearchPaths, which are described on MSDN.

Something like the following:

<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:

For what it's worth, I was able to get NAnt 0.86 working with .NET 3.5 by adding the following to NAnt.exe.config. After doing so, this bit in my build file inside the project tag was all I needed.

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

Added to 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:

I have doing configuration management with Nant and CC.Net for a while now. I my experience I would not recommed using the Nant MSBuild task, instead the easiest way is creating and task, create a .bat file that the task executes. There are several reasons that would recommend using the command line Visual Studio, for one MSI packages are not easily build with Nant, even if you use contrib. Its just way easier and a lot faster this way.

---------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