Nant, using references to the assembly .NET 4.5 (Beta), despite the fact that you specified "net-4.0",

After installing .Net 4.5 Beta, the output of my Nant build failed:

"Failed to load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089'."

because as the answer in this question ExtensionAttribute was transferred to the mscorlib.dll file from System.Core.dll , therefore .net4.5 assemblies are built in the nant assembly, despite the fact that I set the target structure in the nant build script as follows:

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

In Visual Studio, the assembly works fine (creates a DLL that does not require .Net 4.5). But I need a build to work with nant, because we have "old schoolchildren", and also to create processes that use nant.

What do I need to add to my nant build script to make the build actually equal 4.0?

+7
source share
3 answers

Yesterday, I installed VS 2012 side by side with VS 2010 and after recompiling and deploying a web project, it failed with the same exception. After an hour of research, I found a solution.

First you need to edit nant.exe.config

Open it and find:

 <framework name="net-4.0" 

Its OK. on line 555 (in the default configuration for NAnt 0.92)

You will see a huge xml describing the compilation of net-4.0. Find the three children of the <reference-assemblies> . The first two look like

 <reference-assemblies basedir="${path::combine(installRoot, 'v4.0.30319')}"> <reference-assemblies basedir="${path::combine(installRoot, 'v4.0.30319')}/WPF"> 

and the third -

 <reference-assemblies basedir="${environment::get-folder-path('ProgramFiles')}/Reference Assemblies/Microsoft/Framework/.NETFramework/v4.0"> 

And now - just edit the first two to fit the third (copy from the third and paste-replace the 1st and 2nd). After that, NAnt will look for all the DLL files in the Reference Assemblies folder (instead, Windows / Microsoft.NET / ... is "broken")

Do not worry about the /WPF suffix in the second - in Reference Assemblies all files are in the same folder without the / WPF subfolder.

Second step - change your build script

When invoking the csc task csc add two attributes nostdlib and noconfig :

 <csc target="..." output="..." nostdlib="true" noconfig="true" ...> 

This will disable the automatic binding of the bad new mscorlib and other librares from the csc folder.

And inside the <references> element - manually add mscorlib.dll, system.core.dll and all used system libraries. NAnt will find them in the Referenced Assemblies folder:

 <references> <include name="mscorlib.dll"/> <include name="Microsoft.CSharp.dll"/> <include name="System.dll"/> <include name="System.Configuration.dll"/> <include name="System.Core.dll"/> ... 

After this (and, of course, rebuilding), my site was successfully launched on the hosting machine with the "original" .NET Framework 4. :)

PS It looks like Microsoft has reinvented the DLL HELL :)

+10
source

You may have to do two things (I have not tried this at all, but I remember that it helped when 4 was released). First, modify nant.exe.config and add the version to the supported versions of the framework in the startup section of the configuration file (I think that where they go, this should be obvious after opening it). Then upgrade to the latest and largest version of NaNT. And then do something like this in the build file:

 <property name="assembly-location" value="${framework::get-assembly-directory('net-4.5')}" /> <property name="dotNetReferenceAssemblyPath" value="${assembly-location}\" /> 

Again, it has been a while, and I'm not 100% sure that it will do it, but it may lead you to the right path.

+1
source

In principle, Dmitry’s solution is correct, but I had to change it a bit before I could compile .NET 4.0 assemblies on my Windows Server 2012. I used the latest version of nant-0.93-nightly-2013-10-20 in my environment.

  • In the output of the Visual Studio 2013 build, you can see that CSC runs with the / noconfig and / nostdlib + flags for .Net 4.0 target. This proves that your decision is valid.

  • basedir = "$ {environment :: get-folder-path ('ProgramFiles')} ..." does not work for me, because NAnt.exe is a 64-bit process. In fact, most standard builds are only available in the root folder of Program Files (x86). I tried to process NAnt.exe, but it caused other problems. To ensure that the main assemblies can be located with both 32-bit and 64-bit processes, I created the C: \ Nant \ Microsoft.Net \ v4.0 directory and copied them there. Since the directory is not lower than Program Files, it is always displayed.

  • Our assembly of the NAnt script is huge, and I don't want to manually change the links for each csc task. To reduce the necessary changes to the script, I slightly adjusted NAnt 0.93 at night. If the target structure name is "net-4.0" and the task is of the CscTask type, it automatically adds the mscorlib.dll, System.dll files and all system assembly references found in the csproj directory located in the root directory of the csc task sources. The source code and binary configuration files can be found here: http://support.decos.nl/berend/NAnt-0.93-nightly-2013-10-20-modified.zip

The modified code records the added links to the output of the NAnt assembly:

 Inserted reference System.Data.dll Inserted reference System.Xml.dll Inserted reference System.configuration.dll Inserted reference System.dll Inserted reference mscorlib.dll [csc] Compiling 11 files to '... 
+1
source

All Articles