Adding dll to release - c#

We have completed development of our first big application in C# and we need to export it. Our app should work by just opening the .exe file. There may be some other files in Source folder, it does not matter(dll can be next to .exe).
We released it in Visual Studio and it work just fine on our computers, but when we move it somewhere else, it does not work. It is probably caused by ODAC (library for work with oracle database), that is not installed on other pc, where we are trying to run it.
How can we add the dll to release? I could not understand any answers that i've found about this topic. We dont need to merge the dll to exe, dll can be extern file. ODAC was added to project References and it has stored way on our computers, i guess that this can be the problem.
it also pop this
It is very strange for me, that the release is runnable without any problem on our pc's but not on any other (i am sure guy who is testing it for me has .NET framework)

Right click on the reference in question, then choose Properties. Ensure that your references are set to "Copy to Output Folder"=> Always. That's going to put the necessary dlls in your bin folder. Also ensure that the required version of the .NET framework is installed on the target clients.
edit: as #RonBeyer stated in a comment, how do you know it's not working? I kinda glossed over that very important part in telling you how to ensure your DLLs were copied appropriately

Related

How to clean up my VS2015 release files

I'm new to c#, and i'm stunned by the amount of files that are generated by my release output.
I wrote a REALLY simple program that i want to distribute, no external assets or anything special.
but still, there are 10-15 files generated (.dlls, .pdbs, .configs, etc. etc.)
I did a little research yesterday and i got the impression that it is simply not possible to clean up this mess without a REALLY big hassle?
i tried Fody (didn't work at all) and Tidybin (or something like that?) (created a lib folder and put everything there, which was nice, but the program stopped working and threw errors about the missing files)
I'm looking for a way to generate a clean release version.
ideally with JUST my exe, with all the dlls and other stuff embedded, but everything i read about that was just way above my head and overly complicated (why isn't this super easy to do???)
if that's not possible, i'd be happy with moving everything except the .exe in a lib folder. but that didn't seem to work. how do i update the path inside my application, so that those files can still be found? like i said, that plugin seemed to do half the job, while leaving all links like they were.
(side note: why is there not ANY KIND of ducomentation for all of these plugins? i really don't have the SLIGHTEST idea what to do)
thanks
If you have a simple application, there shouldn't really be that much in the folder.
Actually, there should be:
1 exe, 1 pdb (only for debug build), 1 exe.config file for the application
1 exe, 1 pdb (only for debug build), 1 exe.config file for the Visual Studio Host Process
If there is the System.Net.Http library referenced, this could create a folder with many localizations. If you don't use it: Remove the reference.
Please note that you do not need to deploy all these files! If the application only references framework DLLs, all you need is the .exe and .exe.config file.
DLLs will not be embedded, but if they are framework libraries, they should not be added to the output folder unless you set the "Copy Local" property of the reference. And you don't need to deploy them along with your application, as obviously they are installed along with the .NET framework on the target system anyway.
If you reference any DLLs that do not belong to the .NET Framework, you normally deploy them along with your application. It's easiest to put them in the folder along with your application, but you can also put them in the global assembly cache on the target system.
There are solutions that package the executable, third party DLLs and stuff into an EXE wrapper that is unpacked every time you start the application, but I advise against this. The user won't expect this to happen, virus scanners may block this and builtin mechanisms like .NET settings may not work properly for those solutions.
The easiest way to distribute your code is using InstallShield Visual Studio edition. (That is available with your Visual Studio license)
Download and register, then add a new distribution project to your solution.
InstallShield Limited Edition for Visual Studio
A wizard will help you by selecting the main distribution files. And it is a useful tool distributing new releases of your application.
As a second option I use is ClickOnce (Microsoft), but for specific internal applications.
ClickOnce Deployement

DLL Hell(p) - Works on dev box, but not any othe

3 Days of hair pulling. It just doesn't make any sense. I can't figure out what I've missed.
So I have this C#/WPF VS2013pro project I'm building that works fine on my Visual Studio machine: Win 8.1 x64 but fails due to 'dll not found' on any target PC I transplant it to.
It uses FreeImage, which has two DLLs:
FreeImage.dll - C++ that does all the work
FreeImageNet.dll - .NET wrapper to make like easy in C#
The two need to be in the same directory and preferably the same as the .exe - so they are.
My project is 64bit. I downloaded the source for FreeImage and compiled both DLL's for x64: First the CPP one, then the .NET one. Then copied them to the solution.
The .net DLL is referenced in my solution. The CPP does not reference, of course. Both are part of the solution and copy to the %outputdir% (Bin/Debug or Bin/Release) when the solution is built. The program runs fine in DEBUG and in RELEASE on my Development PC and the DLL methods do their job.
I copy the entire BIN directory to another PC running the same version of Windows, same updates, the works... The program runs but when a method is needed from the FreeImage.dll it fails with "unable to find dll".
To make sure I'm right about it using the dll from the BIN directory (and not from System32 or SysWOW64) on my VS machine I pull it out and run the app: Yep it fails.
I put it back and move the entire directory: It works
I pull it out: It fails
I put it back and move it to a thumbdrive: It works
{you get the idea}
So at this point it sure seems like it is really using the one in the same directory as the .exe and the .NET wrapper dll
I move the thumbdrive with the code that just worked on my VS machine to the other PC: It fails.
Next I try remote debug to the other PC: All the files copy to a matched directory, debugging starts and works, I get output and breakpoint behavior from the remote PC: Only the calls that require the DLL again fail because FreeImageNet.dll cannot locate FreeImage.dll
I did nothing special on my Visual Studio machine to make FreeImage work: I downloaded the source and compiled then copied the DLLs to the solution and referenced the .NET dll - That's it.
I have Googled, and researched and opened questions on SourceForge about it.
Every previous question I have found on this issue are cases of someone thinking FreeImageNet.dll was self-contained and not realizing it had to be located along side of FreeImage.dll
I have checked registry for I have checked registry for HKLM/System/CurrentControlSet/Control/SessionManager/KnownDLLs/
I have tried to register it with regsrver32 (yes, the 64bit flavor)
I have tried setting an environmental variable to it.
I have tried copying the DLL to every directory that is part of the DLL search order.
I have tried it on Win8.1x64pro (same as my Visual Studio pc) and two Win7x64pro machines.
I have assumed it was some weird quirk in 3.16 of FreeImage and done this again and again with previous releases as far back as 3.6, all with the same results.
I have built an installer for the solution and installed it on the VS machine where it worked, and installed it on the test machine where it failed.
I am trying for the first time (and not so successfully) to virtualize my physical PC. VMware has always been good to me for test environments and at this point I want to see if a total clone of the Visual Studio machine will succeed or fail with this project.
So... Anyone have an idea?
Darn it, I missed one: vcomp120.dll
Seems it is part of the Visual C++ redistributable that was installed with Visual Studio.
It should have dawned on me that I would need to include this, but with the entire EMGUcv package working... and the fact that I hate C++ and haven't used it in a dozen years... It totally never occurred to me.
Can you please try to import the dll with DLLIMPORT. Copy and place the dll to the directory same as of exe and use following code in Code behind:
[DllImport("FIBITMAP.dll")]
public static extern void Load(string param1,string param2,...);
Here Param1, Param2,... will be your parameters to the function Load.
Hope this helps.

How to make a software portable with C#?

I'm coding a simple application that I need to be portable (the user can just run it by clicking on the .exe without having to run a installer).
All the other questions on this subject that I found on StackOverflow wants to make .NET Framework "bundable" with the software, but I don't need that.
A workaround that I found is going to /bin/Debug on the project folder and use the .exe there, but that seems "wrong". Is there another way to make a software written in C# portable?
Thanks!
EDIT: Okay, I'm really dumb and I asked all the wrong questions. However, your answers pointed me to the right direction. I wanted to know how to generate the .exe to send to my friends. What I had to do is change this to "Release" and press F6. I added this so if someone with the same "doubts" that I had can find the answer easly. Thanks!
Going to bin/Debug and using the DLL there is wrong.
Instead, build and copy the one from bin/Release.
If there's anything else inside the folder, though (except *.pdb), then beware. Your application might need those additional files. For example, the app.config.
All .NET applications are "portable" as long as the machine you are running it on has the version of .NET you are targeting (or a compatible version). The key here is to make sure that your application does not depend on things that an installer would take care of for you to make your application work. Examples include: registered DLLs (like Interop assemblies), registry keys, or components that must be found in certain locations (such as having something stored in user's AppData folder).
As long as the machine you want to run it on has .NET framework, you can make any .NET application portable. If the app you're making has no dependencies other than .NET then it's fully portable already. Even if it does have dependencies just include those with the executable.
To expand on Zerkms's comment:
Every software is portable by default. Installers are a way of telling to program to search for resources in a certain place, meaning that if the place isn't there, eg: C:\Windows then the program won't be able to run.
So as long as you have the application have the resources already within the exe or a root folder search (so where the program is, rather then where it should be) then you'll be fine.
If you're using default controls, it should be fine as long as your software's running framework version is installed on the computer. If you're using 3rd party controls, you can emded the dll's into the .exe upon compiling. Do note that the more dll's you embed, the bigger the .exe file will be.

The source file is different from when the module was built error

I currently have one solution that references ten .dll files. Those .dll files in turn all reference a shared .dll file.
Today I started getting an error while debugging that stated, "The source file is different from when the module was built error.", immediately following a recompile of the shared .dll.
I tried all of the usual. I deleted bin and object folders. I recompiled. I closed all instances of Visual Studio and restarted after they were all closed. I restarted my machine. Nothing fixed seemed to fix it.
I'm guessing one of your 10 DLLs references a different copy of the shared DLL, and not the one you compiled.
Since you have all the sources, put all the projects in the same solution, and have the DLLs reference the shared DLL's project. This will solve your problem.
It has happened to me too. Once I fixed it by recompiling project-by-project from ground up (in the same order that VS does).
Another time this didn't help. I can't remember what I did then.
I believe it is a bug in VS.
I notice you are running VS2008. The problem might go away with an upgrade (the supposed bug might have been fixed). VS2010 is also nicer to work with than VS2008 so it could be areason of its own to stay current. Why not download an evaluation VS11 and try it there.
Move all projects to one solution, reference them in a simple and correct way. Compile. Now you have the right DLLs everywhere and can go back to your more diverse solution(s).
You can also try to use MSBuild. It is easy since you already have the projects in VS. Once it is build by MSBuild (which VS uses itself) it should probably compile in VS again.
Finally you can try to build with nAnt. Once it compiles you can probably compile in VS again.
Good luck. I've been there. It sucks.
I suppose you referencing in your project directly to some DLL, and not a project. Which means if you even cleanup and rebuild, the same dll will be used like a reference.
Very often this is a problem, so I suggesting you check your references.
[edit] Assumed this was asp.net, disregard. [/edit]
Have you deleted everything your temporary .NET folders?
Either in:
C:\Windows\Microsoft.NET\Framework[Your Version]\Temporary ASP.NET Files
or
C:\Windows\Microsoft.NET\Framework64[Your Version]\Temporary ASP.NET Files
When comparing last-modified dates of the shared .dll across output folders of all of the solutions with the file that was stored in the output folder of the primary solution, I noticed that they were not the same as the file that I had just built.
This didn't make sense to me, so I simply copied the new files into the output folder. This did NOT solve the problem. On subsequent builds, the old version was again placed into the output folder, immediately causing the error while debugging...
During compilation, an older version was being pulled along with one of the other referenced .dlls. There is obviously some sort of check that is made with the names of files pulled in so that only 1 file is used, but no check is made for latest version number.
I was able to actually solve the problem by creating a reference to the shared .dll from the primary solution. Direct references are obviously (or perhaps hopefully) pulled in before files that are referenced by references (and are already copied into the same output folder as those referenced .dlls), so the latest file was successfully pulled in first.
If clarity is needed, let me know!
I rarely respond to posts since I am generally too busy, but I just spent a ton of time on this same exact problem. I am running VS 2008 in Windows 7. I had set the my Visual Studio to run in XP Compatibility Mode to fix some issues I had with a different project and forgot to reset it to NOT run in compatibility mode.
Once I removed the Run In compatibility MODE (In Windows Explorer on the DevEnv.exe) my problem with the source being out of sync with the debug information went away.
Hopefully this might help someone in the future with the same problem.

TFS and referenced DLLs

We are using TFS and VS 2010.
I have been working on a project that is using TFS as source control.
I have quite a few dlls that I have downloaded (such as log4net) and referenced in my project.
When a new programmer connected to TFS and got my project out of source control, it failed to build as it said it was missing all these referenced dlls.
What did I do wrong here? How can I include those referenced DLLs in source control.
Do I need to add all these dlls to my project before referencing them? when I referenced them, I just browsed to where they were on my file system.
I've found the best practice for 3rd party DLLs is to create a "Library" folder in your sln/proj file structure and copy all the necessary DLLs into this local folder for reference. You'll also want to make sure these DLLs are checked into source control. This way, everyone who works on the project gets the exact same versions of all DLLs, and the reference paths are exactly the same.
Referencing 3rd party libs in a arbitrary download or install location will be problematic, because it will require all developers to maintain the same download structure for all DLLs. Also, if everyone references DLLs outside of the project structure, it's harder to guarantee that everyone's on the same version.
The other option would be to have everyone install the DLLs into the GAC, but that can be a real pain too, especially with version management and deployment.
I created a "ThirdPartyDLL" folder in my project folder in which I copied all the extra DLLs into it. I then went into source explorer and added those DLLs into the team foundation server so I could be sure I'm using the correct versions of the DLLS for specific versions of my application (and so everyone else is on the exact same page as I am).
View - other windows - Source coontrol explorer
Right click project folder - add items to folder
You won't be able to select a specific folder with DLLs in it, but instead you can select the individual DLL files within the folder. You will then see the "ThirdPartyDLL" folder appear in that window.
Once this is done, those dlls are in the team foundation source control. Whenever a dev checks in, they will get the most current version of the DLLs.
Don't forget to remove the old references in your app and change them to your thirdpartydll folder.
I used to copy the DLLs into the bin folder but the issue I ran into was when the DLLs got upgraded. Initially when my project was small it wasn't a big deal. Now that I have multiple DLLs and applications that I created it became very difficult to maintain consistent versions of DLLs outside my project. My best example is the licensing dll I purchased. When this got upgraded all applications and libraries needed to be on the same version. If I forgot one then I had weird issues or the application just stopped working. Now that I have everything in one folder, I make the change once and everything is upgraded.
Hope this helps.
Andy's suggestion is a good one and I've used that in the past. At my current job, we have a "reference" folder on a network share for all of us to build from. We have a very fast network here, though and all developers are in a single office. This solution won't work as well if you have a lot of remote developers or a slow network.
I've tried various methods for dealing with this and have settled on dropping required dll's in the bin folder and making sure they are included in the project for source control. I've heard people say this might not be a good idea but nobody has provided good reasoning for it and it's worked well for me.
My second choice would be to carve out some space on a network share and organize the various 3rd party dll's there. You can put your files in folders with verion numbers to keep things straight and everyone should have access to everything they need, so long as everyone uses the normal network paths as a reference.
Adding a seperate folder within the project is also workable but seems messy, since you end up with extra files that you don't want included in your release.

Categories

Resources