locked
Option to Add Win32 resource file to project RRS feed

  • Question

  • Hi
     Please, can anyone tell me if this option is available in VB.NET 05/08, I want to add Win32 resource file (.res) to project but i can't find any option to do that, and the option was in C#. This not a regular resource, it was created using  native resources template. Below are the screenshots of Application tab in project property from C# and VB IDE. The option that im looking for is in red box on C# screenshot





    Thanks
    kaymaf
    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    Wednesday, October 7, 2009 4:21 AM

Answers

  • I believe this option does not available in VB.NET IDE

    kaymaf
    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    • Marked as answer by kaymaf Friday, October 9, 2009 12:11 AM
    Wednesday, October 7, 2009 5:17 PM

All replies

  • I believe this option does not available in VB.NET IDE

    kaymaf
    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    • Marked as answer by kaymaf Friday, October 9, 2009 12:11 AM
    Wednesday, October 7, 2009 5:17 PM
  • Go to the solution explorer and right-click the project entry and choose Add/Existing Item. Then select the .res file. The file is added to the project. You can double-click it and it will open and you can use the resource editor to edit/add/remove resources. Right-click the .res entry in the solution explorer and choose "Properties". In the properties window you will see that the "Build Action" is set to "None". The drop list has "compile", "content" and "Embedded Resource". I assume you use the IDE to create the new item and choose "Native resource template" so you might be thinking "Great! I can build this into the DLL as an embedded win32 Resource". But alas, you cannot. The "Embedded Resource" means it will be embedded as a .NET resource.

    If you want to embed the file as a native win 32 resource, you have to use the vb compiler on the command line in order to add the "/win32Resource:my.res" compile switch.

    Sounds easy but I had a heck of a time duplicating the build the IDE ran. I could not get vbc to honor my /platform:x86 entry (I was dumb enough to copy from a MSDN example and replace "anycpu" with "x86"). I finally was saved by the IDE. I noticed the entire command line to the compiler was dumped to the IDE output window. So I copied the line and put it in my bat file.

    Just be aware that if you build from the IDE, you will lose your resources. So remember to always build (or rebuild) using the command line.

    I also have the "register for com interop" option checked and that gave me fits because the IDE output two different sets of files so I had to modify the command line I took from the IDE output window to get the correct file modified. I also added a "regasm /codebase" to my bat file so the dll was registered for com interop. And make sure you set the environment up to the correct VS. Otherwise you may end up running version 1 of regasm and MS changed the DLL assembly format between version 1 and 2 of the .net runtime so that an assembly built with the 2005 compiler cannot be registered with the 1.0 regasm tool. I probably got into trouble because I did not modify the copy of the path to the vbc and accidently used the "VS71commontools". In any case, here is what I ended up with in my bat file. Notice how the /platform entry is followed by quotes - I assume that is where I went wrong (or was it trusting the MSDN)

    ECHO OFF
    CLS

    SETLOCAL
    PUSHD %VS80COMNTOOLS%
    @call vsvars32.bat
    POPD

    D:\Windows\Microsoft.NET\Framework\v2.0.50727\Vbc.exe /noconfig /imports:Microsoft.VisualBasic,System,System.Collections,System.Collections.Generic,System.Data,System.Diagnostics /nowarn:42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 /platform:x86 /rootnamespace:SEAddIn /win32Resource:resTempl1.res /doc:obj\x86\Debug\SEAddIn.xml /define:"CONFIG=\"Debug\",DEBUG=-1,TRACE=-1,_MyType=\"Windows\",PLATFORM=\"x86\"" /reference:D:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.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,obj\x86\Debug\Interop.SolidEdgeConstants.dll,obj\x86\Debug\Interop.SolidEdgeFramework.dll /debug+ /debug:full /out:obj\x86\Debug\SEAddIn.dll /resource:obj\x86\Debug\SEAddIn.Dialog1.resources /resource:obj\x86\Debug\SEAddIn.EdgeBarForm.resources /resource:obj\x86\Debug\SEAddIn.Resources.resources /target:library *.vb "My Project\AssemblyInfo.vb" "My Project\Application.Designer.vb" "My Project\Resources.Designer.vb" "My Project\Settings.Designer.vb"


    regasm.exe /codebase obj\x86\Debug\SEAddIn.dll

    ENDLOCAL

    ECHO Compile Complete

    I know it looks like a mess but remember to just copy from the IDE output window. Note I modified where the output had each .vb file explicity listed and replaced with "*.vb".

    I don't know why the Visual Basic team seems unable to figure out how to add an option to the "Build Action" dropdown like "Native Win32 Resource". Seems pretty simple. Perhaps the C# team has sharper programmers. Either that or VB .NET is a second class citizen and all the R&D money goes to the C# guys.

    Wednesday, October 7, 2009 8:09 PM
  • @RD Holland

     Thanks for reply, Add item from solution explorer does not have the win32 resource option, only the .net resource (.resx) file. I know that compiling source code from VB IDE or VBC from commandline is not perfect like C#.  I think the reason was that C# was related to C++.

    kaymaf
    I hope this helps, if that is what you want, just mark it as answer so that we can move on
    Thursday, October 8, 2009 1:02 AM
  • Your initial question pointed me into the right direction and I finally succeeded in creating a solution that works for me from inside the IDE. I wanted to use a Native Resource file (desirably an icon) together with assembly information.

    Let me summarize it (for you and all the others interested in it):

    • Compile your Exe normally
    • Use Resource Hacker to extract your Assemby Information ("Version Info" node) and Application Manifest (here "24" node) into a Resource Script (RC) file.
    • You should have 2 resource script files and the manifest file (xml) called "Data_1.bin". You can rename "Data_1.bin" to "YourApplication.exe.manifest", both in Explorer and the Resource Script, if you like.
    • Merge the 2 rc files together into one script, eg. name it "YourApplication.rc", and add "ICON1 ICON "some_icon.ico"" at the first line, if you like to use an icon usable by eg. Windows Explorer.
    • Unload your project in Solution Explorer and Edit the project file:
      - Add the attribute "InitialTargets="GetPaths" " to the Project node.
      - Add "<Win32Resource>YourApplication.res</Win32Resource>" to the PropertyGroup sections for compilation (here three: Active Configuration, Debug, Release)
      - Add the following nodes to the Project node:
        <Target Name="GetPaths">
          <GetFrameworkSdkPath>
            <Output TaskParameter="Path" PropertyName="FrameworkSdkPath" />
          </GetFrameworkSdkPath>
          <CreateItem Include="$(FrameworkSdkPath)bin\rc.exe" Condition="'@(RcExe)'==''">
            <Output TaskParameter="Include" ItemName="RcExe" />
          </CreateItem>
        </Target>
        <PropertyGroup>
          <PostBuildEvent>
          </PostBuildEvent>
          <PreBuildEvent>"@(RcExe)" "$(ProjectDir)$(TargetName).rc"</PreBuildEvent>
        </PropertyGroup>
    • Reload your project and Build it.
    The Resource Compiler compiles the Resource Script into a Native Resource file, then the project is built as normal and the linker adds the Native Resource file to the Exe file.

    Sticking points:
    • You have to update the Win32Resource node and rename files, when changing Project/Assembly Name.
    • You have to update the "Version Info" in the resource script manually, when AssemblyInfo information (eg. assembly version number) changes.

    Friday, March 5, 2010 12:20 PM
  • @ Thomas_D, Thanks for the information.  There is no need to use resources hacker, this can be done with VS IDE. You can take look at this thread

    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/938e1091-3529-4f42-b802-3d619625a6f5

    kaymaf

    CODE CONVERTER SITE

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

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

    Friday, March 5, 2010 12:59 PM