Why third party library "ChilkatDotNet4x64" isn't copied to the output folder? - c#

I have project A that references third party library ChilkatDotNet4.dll. My project B references project A. After the compilation the output folder of B contains ChilkatDotNet4.dll as exptected! But, when I replace ChilkatDotNet4.dll to ChilkatDotNet4x64.dll, so the later isn't copied to the output folder. Why?
Copy Local is set to True, solution is compiled to Any CPU
At first I thought it must be something with Copy Local (explained here), but hey(!) it does work with ChilkatDotNet4.dll version. So what is the problem with ChilkatDotNet4x64.dll?

If you are using a Build Template make sure to add the file manually. A work around if you can't find what a build template is, is to rename the file from ChilkatDotNet4x64.dll to ChilkatDotNet4.dll

Related

Referenced project's necessary files not copied to the release folder

I have a solution made out of 2 projects. One is A which is my main project and one is B. A has a reference of B in it. So when I build the entire solution, B's .exe file is created in the release folder. But B also has reference to some .dll libraries that are also needed for the program to be working. And they do not appear in the release folder.
How can I change my build properties so that all the necessary files will be copied so I don't have to copy them manually every time?
The quick and dirty way is to manually add B's dependencies into A's project.
A less error prone way would be to have a single common bin folder that both projects output to. You set B to build into it and then A references the B dll from there so all the transitive dependencies are put in place just by building B.
Yet another approach would be to get B to build a Nuget package (which then describes its dependencies) and then use Nuget to add B as a package to A and it'll sort the rest out for you.

Automatically copying dll.config to a referenced projects output directory

I used the method suggested in the following post to include an App.config file to Class Library project.
Equivalent to 'app.config' for a library (DLL)
It works as mentioned and creates the .dll.config file in respective Class Library projects output directory (e.g. ApiCommunicator\bin\Debug).
I have referenced this Class Library project as a "Project Reference" from another Console Application project within the same Visual Studio solution.
Now the problem is, the .dll is getting copied to the Console Projects output directory (i.e. Engine\bin\Debug) but the .dll.config doesn't. If I manually copy it, everything works fine but is there a way to configure Visual Studio to auto copy .dll.config to any other project's output directory which references the Class Library project?
Thanks,
Bathiya
Although I am late, but my answer can help others. I used the following command as pre-build event:
copy /Y $(SolutionDir)\[YOUR_LIBRARY_PROJECT]\app.config $(ProjectDir)$(OutputPath)[YOUR_LIBRARY_NAME].dll.config
I tried to be dynamic as much as possible, and the above command worked.
I posted the same answer at the question Can we autocopy the *.dll.config? as well.
It would have to be the other way around: Projects referencing your dll could copy it's dll.config from a known location as a post-build event.
However I think it would be much better to provide the configuration from within the consumer application's configuration. That way each referencing project would have an option to adjust the configuration to its needs, which I would think is a critical feature.
If that is not the case, then I don't see the reason for having the .dll.config, and you can just hardcode the values.
You can use the 'Build Events' tab of your project properties to run command line instructions post-build or even pre-build. This way, you can use a simple
copy /Y "<yourconfigfilepath>" "<yourprojectfilepath>\Engine\bin\Debug\"
This will copy the dll.config file you are needing over to the correct directory.

Possible to remove and add a reference to csproj programmatically via a batch file?

I am writing a short batch file to prepare a control library DLL with Examples project for deployment via sip file and have the following question.
Given a csproj file at known location and a DLL at known location, is it possible to programmatically update the csproj from the batch file (via third party command line exe, or other scripting) to add the new DLL?
My folder structure is
/Build
/SDK
/WPF
/4.0 : ControlLibrary.dll sits here
/Examples
/WPF
/4.0 : Examples.csproj sits here
Assuming the batch file is at the /Build level, is there any way to modify Examples.csproj to reference ControlLibrary.dll ?
Just to clarify, the reason why I have the structure like this is I wish to deploy an examples csproj to ship with my control library. Examples.csproj should reference the obfuscated control library under SDK/. Examples.csproj also exists on dev trunk (where it has been copied from) and in the development solution it references output of ControlLibrary.csproj on non obfuscated form.
Essentially what im creating here is a folder structure to zip up and ship the ControlLibrary plus examples, hence, the need to update the reference.
Update - Solved using Powershell
Please see this related question and answer on adding and removing references using Powershell
csproj files are XML files - you can easily write a command line application to manipulate these files (adding, removing nodes etc).
You can call such a command line application from your batch file.
You can find the schema for this file at:
%windir%\Microsoft.NET\Framework\[framework version]\Microsoft.Build.xsd
As described in this SO answer.
I don't understand why you would need to modify the csproj file in your case. Just make sure the library reference in the csproj file is relative, i.e. ..\..\..\SDK\WPF\4.0\ControlLibrary.dll and it will keep working fine even if you move the complete folder hierarchy to a new location.
If you're trying to simplify adding the library to new projects though, take a look at NuGet. It's the best way for distributing and deploying libraries.

Possible to package all needed files in an EXE?

I wrote an EXE that uses a third party dll and a template excel document. Anytime someone uses it they have to copy all three files (which is a pain).
Is there any way I can package everything that is needed into the EXE so there is only one file to worry about?
This is something that ilmerge is used for, atleast for combining assemblies. There is more information here and here.
There are several known problems with this though.
Yes - drag it into your project resources (My Project > Resources tab) and from there you can access it using global::Resources.resourceFile (I think - that might not be the right syntax, an alternative is here) as a byte stream and write it locally from there.
You can add files to your project in visual studio and set Build Action to None and Copy to Output directory to Copy always.
or
You can add these files to assembly resources. Adding and Editing Resources (Visual C#)
I suggest doing the first.
Also, for 3rd party dll: set Copy Local to true for the reference.
After you have your project set like this. Create setup project in VS and it will make one exe as you want.
How to: Create or Add a Setup Project
Software installation is a pain, but I think you can get away with an xcopy style deployment by using the compression tool of your choice (like winzip) and creating a self extracting executable.

C# lib install?

I downloaded two different packages, they both came with an .XML and a .DLL file. I used some of their source code and couldn't get it to work (missing namespace). How do I install the XML file and the DLL file? I know the dll should go into system32/system but what do I do with the xml file?
You don't need to install the DLL at all, actually. Just add it as a Reference to your project, then use it as normal.
The XML file isn't specifically necessary. It can be used to generate documentation for the DLL, if you so desire.
EDIT: Also make sure that "Copy Local" (or something similar, can't recall the exact wording) is set to True in the properties of the reference. This will ensure that the DLL is in the same directory as your exe. Otherwise it probably won't be in the load path and then your app won't run.
You don't need to put it on any particular place (that system32 comment is an older technology).
Based on the issue you mentioned (missing namespace -> when compiling), you just need to add the reference to your project (right click on project->add reference->browse->select the .net dll).

Categories

Resources