0

I am analyzing a .NET Framework assembly using ILSpy. I noticed a Resources folder that contains many DLLs and *.tx files. These resources are copied to the output folder when you have the assembly in your VisualStudio project references.

I need to replicate this behavior in my own assembly, how and where should I add these files in my VisualStudio project?

The original assembly is a .NET Wrapper and the DLLs inside the resource folder are unmanaged C/C++ ones.

Thanks.

enter image description here

abenci
  • 8,422
  • 19
  • 69
  • 134
  • 2
    You can add them as embedded resources and then attach a handler to the AssrmblyResolve event that extracts them at runtime. Or you might want to check out Fody.Costura which does all the lifting for you. Note that either case only really works (or rather, works best) within the context of an application and not a class library. https://github.com/Fody/Costura Costura can handle unmanaged dlls. Doing it yourself I think would prove more difficult – pinkfloydx33 Jul 02 '18 at 08:46
  • Can you elaborate better the _attach a handler to the AssemblyResolve event_ in a final answer? – abenci Jul 02 '18 at 10:04
  • No because I'm not entirely sure if/how it works with unmanaged assemblies. Obviously it's possible since costura can handle it but any answer I could provide would be a guess at best – pinkfloydx33 Jul 02 '18 at 10:06
  • Has your recommendation something to do with this post? https://stackoverflow.com/questions/9099309/where-to-handle-assemblyresolve-event-in-a-class-library – abenci Jul 02 '18 at 10:52
  • Can this one be another solution? https://stackoverflow.com/questions/13031778/how-can-i-extract-a-file-from-an-embedded-resource-and-save-it-to-disk – abenci Jul 03 '18 at 08:29

1 Answers1

0

We finally resolved with this Visual Studio C++/CLI project and its AssemblyLinkResources section:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{FF5EF878-3A80-4DD6-B795-8548ED621BC0}</ProjectGuid>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    <Keyword>ManagedCProj</Keyword>
    <RootNamespace>CopyModules</RootNamespace>
    <SccProjectName>SAK</SccProjectName>
    <SccAuxPath>SAK</SccAuxPath>
    <SccLocalPath>SAK</SccLocalPath>
    <SccProvider>SAK</SccProvider>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>DynamicLibrary</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v110</PlatformToolset>
    <CLRSupport>true</CLRSupport>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
    <LinkKeyFile>..\..\..\Control\Source\Control.snk</LinkKeyFile>
    <TargetName>CopyModules</TargetName>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <PrecompiledHeader>Use</PrecompiledHeader>
    </ClCompile>
    <Link>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <AdditionalDependencies />
      <AssemblyLinkResource>modules\libcrypto.dll;modules\sisl.dll;modules\TD_Alloc_4.3_11.dll;modules\TD_Db_4.3_11.dll;modules\TD_DbRoot4.3_11.dll;modules\TD_DynBlocks_4.3_11.tx</AssemblyLinkResource>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <ClInclude Include="CopyModules.h" />
    <ClInclude Include="resource.h" />
    <ClInclude Include="Stdafx.h" />
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="AssemblyInfo.cpp" />
    <ClCompile Include="CopyModules.cpp" />
    <ClCompile Include="Stdafx.cpp">
      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
    </ClCompile>
  </ItemGroup>
  <ItemGroup>
    <ResourceCompile Include="app.rc" />
  </ItemGroup>
  <ItemGroup>
    <Image Include="app.ico" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>
abenci
  • 8,422
  • 19
  • 69
  • 134