locked
How to compile a single class into an existing project RRS feed

  • Question

  • I have a VB.NET solution (call it S1) which produces a .vb file (say File1.vb) to be compiled and then included in another solution (S2). S2 is a console app which I want to run from a cmd prompt, not VS. My plan is to shell out from S1 to run a batch file to do the compile and then copy the .dll file, overwriting the old one in S2 (then I can run S2 in a separate operation). Here's the batch file for the compile:

    vbc /target:library "C:\Users\Richard\Documents\Visual Studio 2008\Projects\SNOBOL4\SNOBOL4\SNOBOL4Program.vb" 
    /libpath:"C:\Users\Richard\Documents\Visual Studio 2008\Projects\SNOBOL4.NET\SNOBOL4.Net.Common\bin\Release";"C:\Users\Richard\Documents\Visual Studio 2008\Projects\SNOBOL4.NET\SNOBOL4.Net.Runtime\bin\Release" /reference:SNOBOL4.Net.Runtime.dll,SNOBOL4.Net.Common.dll

    Move "C:\Users\Richard\Documents\Visual Studio 2008\Projects\SNOBOL4\SNOBOL4\SNOBOL4Program.dll" "C:\Users\Richard\Documents\Visual Studio 2008\Projects\SNOBOL4Run\SNOBOL4Program\bin\Release\"

    I'm getting a couple of errors that I don't understand. First:

    C:\Users\Richard\Documents\Visual Studio 2008\Projects\SNOBOL4\SNOBOL4\SNOBOL4Pr
    ogram.vb(4) : warning BC40056: Namespace or type specified in the Imports 'SNOBO
    L4.Net.Common' doesn't contain any public member or cannot be found. Make sure t
    he namespace or the type is defined and contains at least one public member. Mak
    e sure the imported element name doesn't use any aliases.

    Imports SNOBOL4.Net.Common
            ~~~~~~~~~~~~~~~~~~

    Also:

    C:\Users\Richard\Documents\Visual Studio 2008\Projects\SNOBOL4>/libpath:"C:\User
    s\Richard\Documents\Visual Studio 2008\Projects\SNOBOL4.NET\SNOBOL4.Net.Common\b
    in\Release";"C:\Users\Richard\Documents\Visual Studio 2008\Projects\SNOBOL4.NET\
    SNOBOL4.Net.Runtime\bin\Release" /reference:SNOBOL4.Net.Runtime.dll,SNOBOL4.Net.
    Common.dll
    The filename, directory name, or volume label syntax is incorrect.

    BTW, this code compiles in Visual Studio.

    My original plan wasn't to have a separate project (and therefore DLL) for this one class, but rather replace it in the main project (the one with the module containing Sub Main). Is that possible? The compiler seems to create a DLL from the single class you specify, but that's obviously not the norm; VS creates a DLL containing all the classes in a project. Maybe I can specify the project file for the compilation?

    Thanks for your help.


    Thursday, March 18, 2010 4:26 PM

Answers

All replies

  • Do you want to compile file1.vb into dll or exe file using vb compiler (vbc) from command line prompt. Read this articles on command line prompt. This articles was on C# compiler but there is no big different from Vb compiler. Take a look at and see how to compile multiple files into 1 exe or dll.

    http://msdn.microsoft.com/en-us/library/ms379563(VS.80).aspx

    kaymaf

    CODE CONVERTER SITE

    http://www.carlosag.net/Tools/CodeTranslator/.

    http://www.developerfusion.com/tools/convert/csharp-to-vb/.

    • Marked as answer by Jeff Shan Friday, March 26, 2010 1:54 AM
    Thursday, March 18, 2010 5:47 PM
  • The code may compile - but you may be supressing some warnings in VS.

    Rebuild the project in VS containing this file and then look at the output window - you should find the VBC command line it is using the compile this, an example below:

    D:\Windows\Microsoft.NET\Framework\v3.5\Vbc.exe /noconfig /imports:Microsoft.VisualBasic,System,System.Collections,System.Collections.Generic,System.Data,System.Drawing,System.Diagnostics,System.Windows.Forms,System.Linq,System.Xml.Linq /optioncompare:Binary /optionexplicit+ /optionstrict:custom /nowarn:42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 /optioninfer+ /rootnamespace:WindowsApplication4 /doc:obj\Debug\WindowsApplication4.xml /define:"CONFIG=\"Debug\",DEBUG=-1,TRACE=-1,_MyType=\"WindowsForms\",PLATFORM=\"AnyCPU\"" /reference:"D:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll","D:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll",D:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll,D:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Deployment.dll,D:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll,D:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll,D:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll,D:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll,"D:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /main:WindowsApplication4.My.MyApplication /debug+ /debug:full /filealign:512 /out:obj\Debug\WindowsApplication4.exe /resource:obj\Debug\WindowsApplication4.Form1.resources /resource:obj\Debug\WindowsApplication4.Resources.resources /target:winexe Form1.vb Form1.Designer.vb "My Project\AssemblyInfo.vb" "My Project\Application.Designer.vb" "My Project\Resources.Designer.vb" "My Project\Settings.Designer.vb"

    This shouws you the references and imports it is using - compare this to what you trying to use.   Some may not be needed - ie. filealign, debug etc. 

    My initial thoughts are you reference is incorrect - have you tried fully qualifying the dll path.   This sounds as though it would remedy both the the imports and filename incorrect issues and would be a likely cause.

    You can specify a project for compilation - but you would use MSBuild <project name> not VBC to build the project, ultimately MSBuild would use VBC.

     

    Saturday, March 20, 2010 2:19 AM
  • The feature to build seperated classes is called the Class Library.

    You create it by doing when your project is open

    File -> Add -> New Project -> Select Class Libary (an empty class is created for you).

    To reference this Class Library in your solution you can do

    Project -> References -> Projects and select the library.

     


    Success
    Cor
    Saturday, March 20, 2010 8:07 AM
  • As far as I see your output, I think you have your command in multiline.

    One proof: C:\Users\Richard\Documents\Visual Studio 2008\Projects\SNOBOL4>/libpath:"C:\User

    Open your file in Notepad, Click Format Menu and Uncheck Word Wrap, now make sure your command is in single line. 


    Arjun Paudel
    Saturday, March 20, 2010 3:52 PM