AArnott / Library.Template

A template for a NuGet package with tests, stylecop, fxcop, versioning, and Azure Pipelines build ready to go.
MIT License
131 stars 26 forks source link

Running Tests using Visual Studio Test Explorer on net472 with unsigned dependencies #54

Closed SteveBush closed 4 years ago

SteveBush commented 4 years ago

I'm using your template in a solution that targets net472;netcoreapp2.1;netcoreapp3.1. One of the src projects includes a dependency on Nitro.AsyncEx.Coordination which is not strong name signed.

When I run a test project locally using Visual Test Explorer and targeting net472, I get the following error:

 Source: CoreGatewayIntegrationTests.cs line 86
   Duration: 1 ms

  Message: 
    System.IO.FileLoadException : Could not load file or assembly 'Nito.AsyncEx.Coordination, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)
  Stack Trace: 
    NetworkGateway.ctor(IPureNetworkServices networkServices, IPureNetworkAddressInfo networkAddressInfo)
    CoreGatewayIntegrationTests.ctor(ITestOutputHelper testOutputHelper, PureTestFixture`1 testFixture) line 79

Tests work fine for .netcoreapp2.1 and netcoreapp3.1 and in GitHub Action and Azure pipeline builds so it's just locally using Visual Studio Test explorer and targeting net472.

I have tried the app.config trick by adding the following and including it in my test project.

<configuration>
  <appSettings>
    <add key="xunit.shadowCopy" value="false"/>
  </appSettings>
</configuration>

It still doesn't work. If I strong name sign the dependencies manually or with the StrongNamer package then everything works.

Any advice on how to work around this issue would be appreciated.

Thanks.

AArnott commented 4 years ago

.NET Framework won't load a strong named assembly that references one without a strong name. You can file a bug against the library you consume expressing your wish that they start strong name signing. You can stop strong naming your own assembly to get working. This is fine for an application. But if you're writing a library for others to reuse, you'll be further propagating the limitation that others cannot strong name sign if you don't sign yours.

The strong name signing is done in the template based on an snk file. If you delete it and all references to it, your projects will stop strong name signing.

SteveBush commented 4 years ago

This is what I thought. If I want to keep strong naming my libraries then I need to either get the dependency library to sign their assemblies or sign the dependent assemblies as a part of the build using a tool like StrongNamer. I've got this working with StrongNamer but it does not handle dependencies and build concurrency well. I often have to build a couple of times to fix all of the dependencies as both the source library and consuming .NET framework test application need to have all assemblies signed.

Thanks again.