Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSBuild fails if assembly being tested references Microsoft.AspNetCore.Cryptography.KeyDerivation #166

Closed
nwoolls opened this issue Aug 1, 2018 · 10 comments
Labels
needs more info More details are needed

Comments

@nwoolls
Copy link

nwoolls commented Aug 1, 2018

MSBuild fails if the assembly being tested references Microsoft.AspNetCore.Cryptography.KeyDerivation. The error is:

/Users/jdoe/.nuget/packages/coverlet.msbuild/2.1.1/build/netstandard2.0/coverlet.msbuild.targets(15,5): error : Failed to resolve assembly: 'Microsoft.AspNetCore.Cryptography.KeyDerivation, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' [/Users/jdoe/src/tmp/coverlet-fails-to-resolve-KeyDerivation/xunit-tests/xunit-tests.csproj]

Steps to Reproduce

Execute from CLI:

mkdir coverlet-fails-to-resolve-KeyDerivation
cd coverlet-fails-to-resolve-KeyDerivation

mkdir classlib
pushd classlib
dotnet new classlib
dotnet add package Microsoft.AspNetCore.Cryptography.KeyDerivation
popd

mkdir xunit-tests
pushd xunit-tests
dotnet new xunit
dotnet add reference ../classlib/classlib.csproj
dotnet add package coverlet.msbuild

Replace the contents of classlib/Class1.cs with:

using Microsoft.AspNetCore.Cryptography.KeyDerivation;
namespace classlib
{
    public class Class1
    {
        private const KeyDerivationPrf prf = KeyDerivationPrf.HMACSHA512;
    }
}

Execute from CLI (should still be in xunit-tests/ directory):

dotnet test /p:CollectCoverage=true

Expected Result

Build started, please wait...
Build completed.

Test run for /Users/jdoe/src/tmp/coverlet-fails-to-resolve-KeyDerivation/xunit-tests/bin/Debug/netcoreapp2.1/xunit-tests.dll(.NETCoreApp,Version=v2.1)
Microsoft (R) Test Execution Command Line Tool Version 15.7.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

Total tests: 1. Passed: 1. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 2.6021 Seconds

Calculating coverage result...
  Generating report '/Users/jdoe/src/tmp/coverlet-fails-to-resolve-KeyDerivation/xunit-tests/coverage.json'

+----------+--------+--------+--------+
| Module   | Line   | Branch | Method |
+----------+--------+--------+--------+
| classlib | 0%     | 0%     | 0%     |
+----------+--------+--------+--------+

Actual Result

Build started, please wait...
Build completed.

/Users/jdoe/.nuget/packages/coverlet.msbuild/2.1.1/build/netstandard2.0/coverlet.msbuild.targets(15,5): error : Failed to resolve assembly: 'Microsoft.AspNetCore.Cryptography.KeyDerivation, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' [/Users/jdoe/src/tmp/coverlet-fails-to-resolve-KeyDerivation/xunit-tests/xunit-tests.csproj]
Test run for /Users/jdoe/src/tmp/coverlet-fails-to-resolve-KeyDerivation/xunit-tests/bin/Debug/netcoreapp2.1/xunit-tests.dll(.NETCoreApp,Version=v2.1)
Microsoft (R) Test Execution Command Line Tool Version 15.7.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

Total tests: 1. Passed: 1. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 2.7978 Seconds

Calculating coverage result...
  Generating report '/Users/jdoe/src/tmp/coverlet-fails-to-resolve-KeyDerivation/xunit-tests/coverage.json'

+--------+--------+--------+--------+
| Module | Line   | Branch | Method |
+--------+--------+--------+--------+
@SteveGilham
Copy link

This is another instance of the problem underlying issue #72 -- the Cecil rewrite with instrumentation needs access to a type definition from a dependency -- in issue #72 it was the NBitcoin assembly, and here it's 'Microsoft.AspNetCore.Cryptography.KeyDerivation, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' -- but can't find it. Unfortunately, nothing about this is logged when the process fails.

For coverlet, the work-round is to run

dotnet test /p:CollectCoverage=true /p:CopyLocalLockFileAssemblies=true

which does the equivalent of a dotnet publish and brings the dependencies into the output binaries folder where they are visible.

@nwoolls
Copy link
Author

nwoolls commented Aug 1, 2018

Thanks @SteveGilham - I can confirm that the work around you've provided works for the example I posted above and for the original project where we encountered the problem.

@hjkl950217
Copy link

@SteveGilham I have encountered a similar problem, after add /p:CopyLocalLockFileAssemblies=true work. thanks.

I watched #72 ,I hope this issue will be resolved soon. /p:CopyLocalLockFileAssemblies=true is only a temporary solution and does not solve the fundamental problem.

@tracker1
Copy link

Using .Net Core 3 preview 8. Neither of the property options mentioned are working.

$ dotnet test -p:AltCover=true -p:CopyLocalLockFileAssemblies=true -p:CollectCoverage=true -p:CoverletOutputFormat=lcov -p:CoverletOutput=../coverage/

/Users/myusername/.nuget/packages/coverlet.msbuild/2.6.3/build/coverlet.msbuild.targets(24,5): warning : [coverlet] Unable to instrument module: /source-path/api-dotnetcore/MyProject.Test/bin/Debug/netcoreapp3.0/MyProject.dll because : Failed to resolve assembly: 'Microsoft.AspNetCore.Cryptography.KeyDerivation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' [/source-path/api-dotnetcore/MyProject.Test/MyProject.Test.csproj]
Test run for /source-path/api-dotnetcore/MyProject.Test/bin/Debug/netcoreapp3.0/MyProject.Test.dll(.NETCoreApp,Version=v3.0)

MyProject.Test.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>

    <IsPackable>false</IsPackable>
    <IsTestProject>true</IsTestProject>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="../MyProject/MyProject.csproj" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="coverlet.msbuild" Version="2.6.3">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.CodeCoverage" Version="16.2.0" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
    <PackageReference Include="Moq" Version="4.12.0" />
    <PackageReference Include="xunit" Version="2.4.0" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="dotnet-reportgenerator-cli" Version="4.2.15" />
  </ItemGroup>
</Project>

@MarcoRossignoli
Copy link
Collaborator

@tracker1 is your project a standard asp.net core one?I would like to repro your issue

@tracker1
Copy link

tracker1 commented Sep 4, 2019

@MarcoRossignoli yes, I'm pretty sure I started with the dotnet new asp.net core template with core 3 preview 6, and upgraded to 8.

@MarcoRossignoli
Copy link
Collaborator

@tracker1 I cannot repro in my local...can you attach your sample or put it in your repo so I can clone e test?

@tracker1
Copy link

tracker1 commented Sep 5, 2019

@MarcoRossignoli I'll try to get it stripped out enough to be able to demo in a private repo and share it with you.

@MarcoRossignoli MarcoRossignoli added the needs more info More details are needed label Oct 7, 2019
@MarcoRossignoli
Copy link
Collaborator

@tracker1 any news...with 3.0 you should find dll directly to output folder and it should work https://github.com/dotnet/cli/issues/12705#issuecomment-535150372

@MarcoRossignoli
Copy link
Collaborator

Close because seem solved, I mean the above issue with reference not found.
@tracker1 feel free to open a new issue with new 3.0 case(maybe try with prod release https://dotnet.microsoft.com/download/dotnet-core/3.0).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info More details are needed
Projects
None yet
Development

No branches or pull requests

5 participants