Thursday, September 15, 2005

Visual Studio.NET and Nant

UPDATE 10/5/2005

I figured out why I was getting the BC2010 error finally. I decided to isolate the failing build project into it's own directory and determine what the differences were between it and the Visual Studio build. As soon as I reloaded the project in VS.NET, I started getting errors that the signature was incorrect on the methods I was implementing for an interface. Upon further investigation I realized that I had renamed the dll in Nant when it was copied to my lib directory. So the interface that I was implementing referenced the DLL as one name internally, MSDocument.dll, and the library I was trying to build had a reference to it as well as MyCompanyDocumentStructures.dll. Although the contents were the same, I assume the name difference affected the signature enough that I was unable to implement it with a different name. Some sort of compiler information on the error would have been much more helpful but at least I know what was going wrong. I guess the moral of the story is to isolate the problem and then compare the vbproj file to the nant build file and figure out where you have differences. I am now looking forward to taking full advantage of Nant without vbc compiler errors.

ORIGINAL
I was recently building my Visual Studio.NET project and became frustrated when the build process failed because one of the services that was part of the project was running. After the 100th time of doing this, I decided that there had to be a better way. I started searching and came up with Nant.

I started the very difficult journey of creating my first Nant build file for my 36 project solution, not a small task and probably not a good way to start this off but I figured that I wanted to learn how to do this to solve my problem. Failure after failure to create one by hand finally led me to use Gordon Weakliem XSLT doc along with XSLTTransformerMG by Michael Gold to create basic scrips from my vbproj files.
tcontinued...

The first issue I found was that the XSLT process misses the correct imports statements and you get a whole host of odd errors like Exception is unknown and other such nonsense. I found out that you actually have to go copy the imports out of the vbproj files and put them in the vbc build command. Then you have to change the case and wha-la, you have a working build script.

Here is what you see in the imports section of the vbproj file:



Here is the compile section of my build script:
[code lang='vb']

define="${define}" optioncompare="${vbc.optionCompare}" optionexplicit="${vbc.optionExplicit}"
optionstrict="${vbc.optionStrict}" removeintchecks="${removeintchecks}" rootnamespace="${rootNamespace}" verbose="true">


















[/code]
I also had to do some tweaking of the vsconvert.xsl file to update it to handle some of the differences with the newest version of Nant. Try it, you will see the weird errors. I also had to make some changes to XSLTTransformerMG so that it takes vbproj files instead of just csproj files (just a mask change). After all of this, I finally get my script the way I want it and get this error:

[code lang='vb']
MyProjectEnterpriseDataAccessLayer:[nant] E:My DocumentsVisual Studio ProjectsMyProjectProjectMyProjectEnterpriseDataAccessLayerMyProjectEnterpriseDataAccessLayer.build
Buildfile: file:///E:/My Documents/Visual Studio Projects/MyProject/Project/MyProjectEnterpriseDataAccessLayer/MyProjectEnterpriseDataAccessLayer.build
Target framework: Microsoft .NET Framework 1.1
Target(s) specified: build

init-Release:

init:

[tstamp] Thursday, September 15, 2005 12:33:39 PM.

compile:

[vbc] 'E:My DocumentsVisual Studio ProjectsMyProjectProjectMyProjectEnterpriseDataAccessLayerMyProjectEnterpriseDataAccessLayer.vb' has been updated, recompiling.
[vbc] Compiling 2 files to 'E:My DocumentsVisual Studio ProjectsMyProjectProjectMyProjectEnterpriseDataAccessLayerbinMyProjectEnterpriseDataAccessLayer.dll'."
[vbc] Contents of D:DOCUME~1jshankLOCALS~1Temptmp2947.tmp.
[vbc] "/imports:Microsoft.VisualBasic,System,System.Collections,System.Data,System.Diagnostics"
[vbc] "/optioncompare:Binary"
[vbc] /optionexplicit
[vbc] /optionstrict
[vbc] "/rootnamespace:MyCompany"
[vbc] /nologo
[vbc] "/target:library"
[vbc] "/out:E:My DocumentsVisual Studio ProjectsMyProjectProjectMyProjectEnterpriseDataAccessLayerbinMyProjectEnterpriseDataAccessLayer.dll"
[vbc] "/reference:E:My DocumentsVisual Studio ProjectsMyProjectProjectlibMyProject DB Translator Interface.dll"
[vbc] "/reference:E:My DocumentsVisual Studio ProjectsMyProjectProjectlibMyProjectDocumentStructures.dll"
[vbc] "/reference:E:My DocumentsVisual Studio ProjectsMyProjectProjectlibMyProjectMasterSharedLibrary.dll"
[vbc] "/reference:D:Program FilesMicrosoft Enterprise Library June 2005binMicrosoft.Practices.EnterpriseLibrary.Common.dll"
[vbc] "/reference:D:Program FilesMicrosoft Enterprise Library June 2005binMicrosoft.Practices.EnterpriseLibrary.Configuration.dll"
[vbc] "/reference:D:Program FilesMicrosoft Enterprise Library June 2005binMicrosoft.Practices.EnterpriseLibrary.Data.DB2.dll"
[vbc] "/reference:D:Program FilesMicrosoft Enterprise Library June 2005binMicrosoft.Practices.EnterpriseLibrary.Data.dll"
[vbc] "/reference:D:WINDOWSMicrosoft.NETFrameworkv1.1.4322System.dll"
[vbc] "/reference:D:WINDOWSMicrosoft.NETFrameworkv1.1.4322System.Data.dll"
[vbc] "/reference:D:WINDOWSMicrosoft.NETFrameworkv1.1.4322System.Xml.dll"
[vbc] "E:My DocumentsVisual Studio ProjectsMyProjectProjectMyProjectEnterpriseDataAccessLayerAssemblyInfo.vb"
[vbc] "E:My DocumentsVisual Studio ProjectsMyProjectProjectMyProjectEnterpriseDataAccessLayerMyProjectEnterpriseDataAccessLayer.vb"
[vbc]
[vbc] Starting 'D:WINDOWSMicrosoft.NETFrameworkv1.1.4322vbc.exe (@"D:DOCUME~1jshankLOCALS~1Temptmp2947.tmp")' in 'E:My DocumentsVisual Studio ProjectsMyProjectProjectMyProjectEnterpriseDataAccessLayer'
[vbc] vbc : Command line error BC2010 : compilation failed : '0xC0000005'

BUILD FAILED

[/code]
I am sure you can only imaging my frustration that this is an unsolvable problem as far as I can tell. I have posted to Nant-users mailing list but I am not confident that I will find an answer. In the mean time I decided to try Nant's build in support for VS.NET sln files. This works well but misses the flexibility of individual project files. I can't define properties to tell it where to get the Microsoft Enterprise Library. Here is my build script for my solution:

[code lang='vb']












[/code]

This works but due to a bug in VS.NET, I have to close vs.net each time I want to run the build script. Maybe someday I will implement a full CruiseControl.NET Server that runs my NUnit tests and Nant build scripts but for now, it's just easier to stop the service and build automatically in VS.NET. I have also heard good things about continuous integration in VS.NET 2005 Team System which will probably replace NUnit and Nant in the near future. Let me know what you think and what your impressions are.

No comments:

Post a Comment