How to link external files using assembly

Let's say you have a class library project that has any number of additional files that should also be included in the compiled assembly (for example, plain text files or even an outdated unmanaged DLL that is completed by the assembly as an interaction layer). Although the attachment of additional files to the assembly itself is relatively straightforward , we have situations where this is impossible or simply undesirable. We should have them as "sidecar" files (i.e. Files with the assembly, possibly in subdirectories relative to the assembly)

Adding these files to the project with the appropriate value for "Copy to output directory" seems to be sufficient for projects that are completely autonomous in the solution. But if a separate project in another solution adds an assembly link, it does not automatically download sidecar files. Is there a way in the project to somehow mark the resulting assembly so that something referencing the assembly also knows that the associated sidecar files must be included? How do you do this?

+7
visual studio
source share
8 answers

You can use al.exe, but there is also a C # compiler option. You want to create a multi-network assembly using the C # compiler option / linkresource. The instructions are here , but the command looks like this:

csc /linkresource:N.dll /t:library A.cs 

Where N.dll is the native DLL that will be moved to where the managed assembly is going (including in the GAC.) The above link has a very clear description.

+2
source share

Have you tried to create a customization for your solution? There you can enable stroller file targeting in the application installation directory.

Another option is to include sidecar files in Assembly resources and disconnect them to disk on first run.

+1
source share

What if you create a merge module containing a library plus its dependencies? Then your installer will have to reference this module, but you will make sure that all the necessary files are present.

+1
source share

I found a much nicer solution that simplifies the use of linkresource and copy links.

+1
source share

Unfortunately, for Visual Studio this is not much built-in support, although I can definitely see a use case.

If you use Subversion for your source control, you can link the external link as a definition of external ones. This will lead to the source code, and you will make the link to the necessary assembly as a link to the project instead of the link to the DLL, and then the copy will return to the conclusions of the catalog rules.

If this is not possible, another solution would be to include the commands in the pre / post-build events of your in-solution project to copy the latest sidecar files from the remote assembly to the assembly. Of course, this is due to the caution that it does not automatically install when you include a DLL in your project; You need to follow the manual steps to configure it.

0
source share

I deal with this a while ago. Its a common problem.

You can create some actions after creation:

http://www.codingday.com/execute-batch-commands-before-or-after-compilation-using-pre-build-or-post-build-events/

Hope this helps ... :)

0
source share

It seems to me that you are using the wrong type of link. There are two types of links: Reference and ProjectReference. A reference is an explicit reference to a specific assembly. ProjectReference is a link to another project (say .csproj).

What you are looking for is a ProjectReference. VS and MSBuild targets are configured by default to work with CopyLocal. If you set CopyToOutputPath true for your "sidecar" files, any ProjectReferences in this project will now also be loaded into the same files.

I'm not sure if you can use ProjectReferences for solutions in the IDE. I deal a lot with MSBuild, where sln files are irrelevant, and as I understand it.

0
source share

What we did in our project was that we created a separate assembly file for all of these materials.

In your assembly file, you can create tags to create the main solution, and then add tags to copy the files you need after assembly.

NAnt is also your option, but right now I'm happy to use Rake as my build / debug automation.

Since it cannot be integrated into Visual Studio, I do this, I create a task (either in MSBuild, NAnt, or Rake) that ultimately runs vsjitdebugger.exe to attach it to my Visual Studio when debugging.

Now these are just my styles, you can create your own style.

0
source share

All Articles