dotnet / dotnet/msbuild

Nuget dependencies not found when using reflection

Open
#4,838 4 comments 0 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

### Steps to reproduce

I have a project P1 containing a class C1 and C2. I publish it as a nuget package P1.

In an another solution, I create a console project P2, add a nuget reference to P1.
The code in the project P2 tries to find by reflection C1.

From Visual Studio (2017 & 2019), I start the P2 project (F5).

### Expected behavior

I should find the type C1.

### Actual behavior

C1 and the P1 assembly does not exists.

If I publish the project, the P1 dll is present and the app works fine.

Still in Visual Studio, if I had a direct reference to C2 in the P2 project, then I can find C1 by reflection.

Visual Studio (msbuild) seems to make 'optimizations' and does not provide correctly the nuget dependencies if they are only used by reflection.

### Environment data
`msbuild /version` output:

```
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise>msbuild /version
Microsoft (R) Build Engine version 16.3.1+1def00d3d for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

16.3.1.50202
```

OS info:
![image](https://user-images.githubusercontent.com/20680042/67275102-27330a80-f4c2-11e9-9038-5bafc7963c64.png)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.