I have a compiled c# assembly that I am registering for COM exposure. In order to import my library into some legacy c++ code the .tlb file needs to be in one of my "include" directories.
Instead of adding my bin directory to the include directories of the project that will use it, and since these projects will always be compiled under the same folder structure, I was wondering if, on compile, it was possible to direct my .tlb file to a specific directory.
In the Project Properties under the Build Events there is a Post-build events section. Here you can apply any command you'd like, including copy.
Here's some example code that will copy a file form the bin\Debug directory to another directory in the C:\ drive.
copy "$(TargetDir)\filename.tlb" "C:\output directory path\"
Use XCOPY in a post-build task.
Related
I have an Asp.Net project (Vb.Net) that references a managed dll (library written in C#). That library project has several unmanaged dependencies dlls in a lib folder (copied into bin/Release/lib folder during build). The library is not a part of the main solution.
My library uses [DllImport] that references an unmanaged dll. But to let the unmanaged dll be found, I call SetDllDirectory():
string path = // don't know how to generate the path
SetDllDirectory(path);
I am struggling with generating the path to the unmanaged dll and its dependencies. I can start with my main project bin folder or something. But what should I do next? E.g. is there a way to copy the unmanaged dlls from the library's bin/Release/lib folder to my main project's bin folder? Or some other solution?
There are two ways you can go about this:
Add the Dlls to the VS project as a file, then set Build Action to None and Copy to output directory as Copy. This should ensure that any external dependencies of the referenced library are copied.
Add a command like xcopy "$(ProjectDir)lib\*.*" "$(OutDir)\" /y /e or xcopy "$(ProjectDir)lib\*.*" "$(TargetDir)" /y to the Build Events section in Project properties. This should copy the \lib directory from the project root to the output.
I am converting multiple .IL files into .cs, Now I want to create a single c# project with these .cs files. And then i want a .dll file for this project.
I have already created a c# project. I created a folder "Application" into this project. Now I am moving all the .cs files into this folder. After compiling this c# project i am getting its .dll file into bin folder.
Is this steps correct?
I use the Nuget Package Costura.Fody for it.
It merges everything into the target .exe, but maybe as Class Project it merges everything into one DLL?
You should give it a try:
https://www.nuget.org/packages/Costura.Fody/
The steps are correct as long as the result satisfies the initial task.
What you described sounds legitimate. Now it's your turn to check if the dll works as intended.
I'm new in Visual Studio 2013 (C#). I know in general it should be avoid putting bin directory in source control. However, in my bin directory, there are lots of dll files. Without this dlls, I can't build my project.
I thought maybe I should create a directory, such as 'lib' to store the dlls. But the fact is NuGet always put dll into the bin directory. Should I manually move the dll from bin to lib?
All I want is to simply put all source codes, resource files and dll files to source control (git). Then my team-mates can pull the project then build it in their machine.
edit on 1/4/2015: provide further details
For example, I installed log4net thru NuGet. After finished, I found 3 new files existed in bin directory:
log4net.dll
log4net.xml
log4net.dll.refresh
I tried to remove bin directory from my project, then rebuild my project, and hope to see that a new bin directory would be built and all dll/pdb/etc files would come back. But unfortunately it didn't happen.
In my understanding, the ideal process would be:
add reference/install package, then certain config info would be recorded and according files would be installed to bin directory;
when build, according lib files would be referenced from bin, if such files not found, VS would get the reference info from some place other than bin and download them again. So that's one of the reasons why we don't need to put bin into source control.
However, I found that's not true in my project.
Actually according to the official .gitignore, I found bin directory as build results is filtered ([Bb]in/). That is to say, even VS knows such directory should be ignored.
Maybe some wrong setting within my project?
I have a project in Visual Studio 2010 and in this project I have a "lib" foleder in which I have the external dll that I need. In this case, the libraries of SQLite.
Well, I can set hte reference to the principal dlls, SQLite.dll and SQLite.Linq.dll. In this case, the dll are copy in the main folder of the application.
However, I need also the SQLiteinterop.dll. I have tried to add a reference to this dll, but I get the error that it is not a valid COM component. So the way that I find to copy the dll is marked as local copy in the properties of the dll that is in the "lib" folder.
However, this copies the dll in a subfolder "lib" in the main application folder and I need to copy in the main folder.
Is there any way to set in visual studio where to copy each dll?
Thanks.
I would suggest using a Build Event, retrievable in the Properties of the Project.
Here you can make a Post-build event which copies the file to the Build folder.
Something like:
copy /Y "$(SolutionDir)lib\$(ProjectName)\sqllitefile.dll" "$(TargetDir)\$(ProjectName)\sqllitefile.dll"
I have a project that acts as wrapper for a 3rd party .exe (it has static methods to create the command line and run the executable). I want to use it in at least a couple of projects in my solution. Ideally, the .exe should only be in that wrapper project (I don't want to have to add it to each project that uses it). Right now I'm trying to get this to work with a web project (.NET MVC) running on IIS 7 but when I use Assembly.GetExecutingAssembly().Location to see the directory that my wrapper is called from I'm in a folder like
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET
Files\"my
project"\65a016fb\ac5f20a7\assembly\dl3\d8de0f10\06e277a2_55b2cd01
and my 3rd party .exe is nowhere to be found. Is it possible to copy files with a reference that do not compile?
Btw, I have set the "Copy to output directory" and "Build Action" properties of my .exe to "Copy always" and "Content"/"Resource"/"Embedded Resource" without success so far.
Try to add an existing files in your projects which use your wrapper. When the dialog box appears, do this:
http://wiki.oxygenelanguage.com/en-w/images/0/0d/AddAsLinkAero.png
Either that or drag neccessary files to your projects from the wrapped with Alt holded.
That will add the files as links. Links are good choice for reusal whenever the original files has to be located in the only place.
Adding files as links in conjunction with setting to that links build action to Content and Copy always to the option of copying them to the output directory should work for your.
If anyone runs into this problem, here's how I got around it:
Add the .exe to your project's resources (right-click on the project,
Properties -> Resources, add file and give it a resource name)
You may now access your .exe as a byte[] (at least if you're building to a dll)
with Properties.Resources.*NameYouGaveYourResource*
Before using your .exe, use File.Exists() to check if the file exists in Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) (or you can put the exe wherever you want using the method, above gets you directory the .dll is in) - if not, write out the file:
using (FileStream fileStream = new FileStream(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\EXE.exe", FileMode.CreateNew)) {
fileStream.Write(Properties.Resources.NameYouGaveYourResource, 0, > Properties.Resources.NameYouGaveYourResource.Length);
}
Now you can use the exe easily as a Process. Pretty far from ideal, but it means the exe accompanies your .dll wherever it goes.