Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using functions and classes in another vb.net project

I'm refactoring my VB project into 2 projects, one being a utility library that I want to share with future projects. My solution's layout is like this:

Solution
|_ util
   |_ util.vb
|_ main project
   |_ (main project files)

util is created as a class library, and the member files added into it. I've then added util into the main project's references. However, when I try to call functions in util.vb from my main project files, I get build errors like this:

error BC30451: Name 'LogException' is not declared.
error BC30002: Type 'VarFile' is not defined.

These are defined in util.vb, and it compiled fine when it was part of the main project. The declarations look like this: (I've trimmed out the details)

Imports System.IO

Public Module utils

    Public Sub LogException(ByRef ex As Exception, Optional ByVal logFile As String = "", Optional ByVal logFolder As String = "")
' ...
    End Sub    

    Public Class VarFile
          ' ...
     End Class
End Module

I can add util.vb "as link" into the main project and it will solve all the build errors, but that seems to defeat the purpose of refactoring out the class library - I would like to develop this library separately, and not always have to keep track of which file links I haven't added in my main project. Is there a better way than this?

like image 832
martin_ljchan Avatar asked Mar 12 '12 06:03

martin_ljchan


2 Answers

create a dll project and make it as your library then add reference to it from main project. all these will come under one solution. Also set the build order. Use Imports to use the function similar to Imports System.IO

like image 79
kbvishnu Avatar answered Nov 15 '22 05:11

kbvishnu


The mechanism you're looking for is References. Right click on the Main project and choose Add Reference, choosing your Util project from the Projects tab. After that, don't forget to add Imports declarations, since the new Util project will be in a different namespace than your Main.

like image 40
Avner Shahar-Kashtan Avatar answered Nov 15 '22 05:11

Avner Shahar-Kashtan