adding project output as embedded resource

Locked adding project output as embedded resource

  • Tuesday, March 06, 2012 4:24 PM
     
     

    I have a Class Library and a Console Application projects in a solution, I need to embed the Console application as a resource with in the DLL.

    Is there a way with VS to do this automaticlly? and such that it will all work with relative paths and during the TFS build which inturn changes the location/path of the actual code, thus causing my working solution (below) to be very complicated.

    I know I can add the output EXE as a file to the DLL, and with some combonation of build events have it updated during the build and have this piece working.

All Replies

  • Tuesday, March 06, 2012 5:07 PM
     
     Answered

    I haven't tried it, but if you add some mock/dummy file in place of the console application to the library project and add a pre-build task to move the output of the console application project to there (or have the console application project buid to there, it should work.

    You can also do it as a MSBuild traget.


    Paulo Morgado

  • Thursday, March 08, 2012 7:31 AM
    Moderator
     
     Answered
    Hi ThisBytes,

    It's worth baring in mind that your uses may not be too happy about you doing this. Embedding an executable that they've got no control over into a DLL that you'll extract and run will probably make people worry about the running a Trojan horse on their machine.
    It's better to leave the .EXE in the filesystem and be transparent about what your application is doing.

    While if you really need to perform this:

    1. Add a resource file to you application (right click application in IDE and select "Add new item".
    2. Use the toolbar in resource editor to add an existing file.
    3. Then extract the exe whenever required by calling code something like: System.IO.File.WriteAllBytes (@"C:\MyEXE\", Resource1.MyEXE);

    Have a nice day,




    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us

  • Monday, March 12, 2012 11:53 AM
     
     

    No users involved here, the need for the embedded EXE is for our internal Installs, we are wrapping the deploy of share point web parts up in to an MSI, this requires us to write a custom action. To prevent having a large amount of steps in a document on how to create the MSI, we were going to embed the EXE in the custom action DLL as well as other files so that there was only one file to add to the MSI projects.

    I also agree that I wouldn't want to do this to an MSI that would go out to regular users, but for internal uses this will work for us.

    As stated above, I've got this working by manually adding the exe as a file, what I want to do is:

    Solution
      Project 1
      Project 2

    Have the result of project 1 be an embedded resource of project 2, without having to go to the folder and choose the resource myself, much in the same way that in a set up project you can add the Primary output of the project to the set up project.

    I want/need to do it this way as simply adding the file adds it based on the path you selected. In the case of my machine it would be from the debug folder, but on the build server it's from a completely differnt folder.

    Is this even possible today in VS?

  • Monday, March 12, 2012 1:59 PM
    Moderator
     
     Answered

    VS does not support changing source paths per configuration like you mentioned.  Technically it can be done if you use an envvar but you'd have to make the change outside VS via a text editor and then ensure no one every modifies the file.

    I think you're trying to solve the problem in the wrong way.  What you're talking about is a system build problem rather than a solution build.  For that I'd lean toward doing most of the work in MSBuild.  You could then build your console application, copy it to the correct location and then build the rest of the system.  All this would be done via MSbuild rather than trying to go through VS proper.  Note that VS will honor the changes so you can still use VS to build but the initial modifications would be done manually outside VS.

    As an alternative (but equivalent) approach you could add a post-build event but I think MSBuild is easier.

    Michael Taylor - 3/12/2012
    http://msmvps.com/blogs/p3net

  • Tuesday, March 13, 2012 6:24 AM
    Moderator
     
     
    Hi ThisBytes,

    So how is it going now with Michael's suggestion?
    We are looking forward to hearing from you.

    Have a nice day,

    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us

  • Tuesday, March 13, 2012 12:34 PM
     
     
    I have the post build event working, that's been working since I asked the question intially, as such I'm going to keep it for now, and won't be researching the MSBuild Event. I was making sure I didn't over look something in VS that would allow me to add the project output.

    Wayne