Is it possible to embed System.Resources.Extensions?

When using the .Net Core 3 build toolchain, certain .Net Framework projects must now include the GenerateResourceUsePreserializedResources attribute as well as a dependency on System.Resources.Extensions ( https://www.nuget.org/packages/System.Resources.Extensions/ ) in order to build, as described in the discussion here: https://github.com/microsoft/msbuild/issues/4704

After adding the attribute and dependency, it seems SmartAssembly (7.1) can't detect System.Resources.Extensions as a dependency (it doesn't appear as any of mergeable, unmergeable, embeddable, or unembeddable), and so it can't be included as part of the resulting obfuscated executable. The project source files don't need to use anything defined in System.Resources.Extensions, so I'm guessing SA either decides that means it's not actually required as a dependency, or something about its interaction with the special-purpose build attribute creates a corner case not accounted for by SA. Is there some element I can add to my project files to force SA to detect it, or do I have to ship System.Resources.Extensions alongside the application?
Tagged:

Best Answer

  • Russell DRussell D Posts: 1,324 Diamond 5
    edited November 5, 2019 10:50AM Answer ✓
    It looks like System.Resources.Extensions is not defined as a reference of the assembly when the GenerateResourceUsePreserializedResources attribute is defined.

    .NET Core 3.0 


    .NET Framework 4.8
    ​ 

    Of course, the assembly is copied to the build directory, so maybe it's used via reflection but I believe that you should copy this assembly manually. For .NET Core 3.0, there is also definition in the deps.json file, but SmartAssembly will not remove this record during a build process.



    When System.Resources.Extension is used by an assembly like:
    namespace Lib
    {
        public class TestClass
        {
            public static void Test()
            {
                var test = new System.Resources.Extensions.DeserializingResourceReader("");
            }
        }
    }
    Then the reference exists and we are able to merge a few assemblies (System.Resources.Extension also):

    .NET Core 3.0

    .NET Framework 4.8
    Have you visited our Help Centre?

Answers

  • littlerklittlerk Posts: 7 Bronze 2
    I tried adding a dummy method referencing DeserializingResourceReader like you suggested, which helped reveal a little about what's happening under the hood:



    It seems that if System.Resources.Extensions is required for dotnet to build the base project, it can't be merged for this reason, but it can still be embedded along with System.Buffers and System.Memory. That will probably be sufficient for our purposes.
  • Thanks for the follow up information, it's very helpful to know how people are using this.
    Have you visited our Help Centre?
Sign In or Register to comment.