I want to use a DLL written in C in a VB project such that the DLL will be copied to the output directory.
I earlier asked this question here and got an excellent answer:
VB.Net using C DLL
All you have to do is go to the Project menu and "Add Existing Item". This works great if you copy any updates to your DLL into the project folder. Now I have a new project, and I put my C project folder inside the Visual Basic project folder in hopes that Visual Basic would fetch the DLL from that folder and copy it to the output directory. Oh no, they would never make it that easy. Adding an existing item copies that file to the project folder. So now it always fetches an old copy of the DLL unless I manually fix this, which I do not want to. How can I make Visual Basic honor my wishes?
When you do the "Add Existing Item..." the Add button has two options, one that will add a Link to an existing file and not copy to your project, but it will copy to the build output.
Related
I'm looking to embed a DLL into the EXE of my WPF application so that I effectively only have 1 file to distribute, i.e. the .EXE. All of this stuff is completely over my head but I've followed the steps outlined in http://richarddingwall.name/2009/05/14/wpf-how-to-combine-mutliple-assemblies-into-a-single-exe/ but I still can't get this to work. Any ideas or help on this? As long as the DLL is in the same folder as EXE it works but if I remove the DLL, it will fail. However, I don't want the DLL to be present at all but rather embedded within the EXE. I've searched other posts here which recommend this solution but my problem is that everything compiles fine, it's just that it doesn't work and I don't know how to go about fixing it.
1) I have added the DLL in question as a resource to the project and set its Build Action to Embedded Resource
2) The code outlined in the above link, I've added to the App.xaml.cs file as well as using System.Reflection & System.IO
Is there anything esle I should be doing to get this to work?
Thanks
Shav
You could use ILMerge. We use it all the time to merge dll's into executable's and into other libraries.
Here's how someone else used ILMerge to accomplish this, so this could be considered a duplicate question.
If you are using Visual Studio w/Nuget, you can simply set your needed reference to 'copy local = true' and install Fody.Costura.
You can refine things a bit using a simple xml file, per the documentation provided on the project page (as well as tidy-up your build directory if desired).
What is the best way to put a DLL written in C into a VB.NET (Express Edition 2010) project? I have the declarations for the external functions locating absolute paths right now like so:
C:\Users\Kyle\Documents\Pelles C Projects\ROBOLIB\ROBOLIB.dll
Because Visual Basic creates so many different directories the program could be running from (Debug, Release, Publish). Is there any way I could tell VB.NET to some files into the program's directory? Or should I somehow customize the installer so it puts the DLLs I need in a specific location?
You can add the DLL to your project (either per Drag'n'Drop or right mouse click -> Add -> Existing Element). If you right click the file and choose properties, you can define "Copy to output directory".
Of course, you should ensure that the installer (in case you create one) copies the files.
This is somewhat silly, but it's been bugging me. I'm developing a Windows Forms application, and I'm using lots of data sources. When I create them, they're automatically placed in the root of my project. For the sake of organization, I've created a DataSources subdirectory and moved them in there.
The trouble is that when I move the .xsd files from the root my the DataSources directory, the project references break and I need to update the designer file in a few places. How do I avoid this?
For new datasources, just create them in the desired subdirectory. That is right click on the subdirectory and create new component there.
For your existing files I believe the location of file is indicated in: xsi:noNamespaceSchemaLocation="your.xsd"
You should be able the change to add path relative to project, something like: xsi:noNamespaceSchemaLocation="../subdir/shiporder.xsd"> or perhaps just: xsi:noNamespaceSchemaLocation="subdir/shiporder.xsd">
I hope this helps
I have a Silverlight project with lots of source files. Now I want to create a new WP7 project using the same source code files (but obviously, target WP7).
I link the WP7 project to the existing Silverlight project using Project Linker. However, this does not automatically generate links to the existing files in the source project.
Is there any way using Project Linker to automatically populate the destination project with the already existing files in the source project? Or do I manually have to add links in the WP7 project to all previously existing files in the source project?
I have the same problem, but I resolved it.
Simply exclude all files from "source" project and then re-include them.
In this way project linker refresh its references adding all links!
It worked for me!
I'm not quite sure what you but I think you'll have to do manually in VS.Net, but if all the files in the same directory you can add all the files in one go, it sounds as though you want to select the 'Add as Link' option once the add 'Existing items' dialog is displayed.
Using Clickonce with VS 2010 and .NET framework Client profile 3.5, I have several file folders with application level XML and/or textfiles that are needed at runtime.
The file folders sits in the same project where they are to be used.
These files are marked as "Copy always" at compile.
Build Action is "Content".
On my development machine the files are actually copied into the ./Bin/Release/myFileFolder/xxxxx and all is fine.
On user's computer, install runs fine but some files are reported missing at runtime when the program need them.
Do I miss something? Is any file specific option deep hidden in the option list?
Help please! and .NET framework 3.5
If the files are in referenced projects then they are not included in the click once publish by Visual Studio. You can verify this by checking the application files dialog in the publish page of the project properties.
Assuming this is the case to get these files included you can either add them as links in the main project itself or edit the project file to include extra files in the manifest. See ClickOnce Content Files for information on how to do this.
I can confirm that this can still be an issue in Visual Studio 2019.
I have been working on DevExpress dashboards that consume XML files at runtime to produce their dashboard layouts, and whenever I would publish my project, I would get a bizarre error about the XML file not being found when clearly it was published to the same output directory as the rest of the project.
Just to be clear, the XML file existed in my Visual Studio project and was set to Build Action = Content and Copy Always To Output Directory.
What I had to do was what was suggested in this answer:
Go to Project Settings.
Open the Application Files list.
Change the Publish Status of the XML file - which Visual Studio automatically set to Data File (Auto) - to Include.
Voila. FileNotFound error magically disappeared after publishing the project.
A workaround is to make your application create the xml/txt files if they dont exist.