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

net45 target causes major build issues in .NET Framework 4.7 projects #719

Closed
bassettb opened this issue Nov 6, 2018 · 7 comments
Closed

Comments

@bassettb
Copy link

bassettb commented Nov 6, 2018

Moq should include a build target for .Net Framework 4.7. This target would not have a dependency on System.ValueTuple. The current 4.5 target causes major build issues in Framework 4.7 projects.

@stakx
Copy link
Contributor

stakx commented Nov 6, 2018

The current 4.5 target causes major build issues in Framework 4.7 projects.

Could you please explain in some more detail just what those issues are?

(P.S.: We've already had several issues asking for certain targets and it's already being considered, so I will likely close this issue as a duplicate.)

@bassettb
Copy link
Author

bassettb commented Nov 7, 2018

The warning is below. It could not be resolved with a binding redirect or by adding the latest System.ValueTuple nuget to our projects. warning MSB3258: The primary reference "myproject.dll" could not be resolved because it has an indirect dependency on the .NET Framework assembly "System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" which has a higher version "4.0.3.0" than the version "4.0.2.0" in the current target framework.

@stakx
Copy link
Contributor

stakx commented Nov 7, 2018

Must be something with your specific setup. Make sure you have the latest versions of everything (VS, NuGet, .NET Framework). It might also help to use <PackageReference> instead of packages.config. If you're using the old .csproj format, make sure you use <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>.

Finally, please note that this type of problem cannot be fixed for everyone on Moq's side. It has to be fixed on the .NET & tooling side. The netfx-compat-tagged issues in dotnet/standard are a testament to how widespread assembly versioning problems have become on the .NET Framework. This post by Immo Landwerth (MSFT) is also a nice write-up although not directly related to net45 vs net47.

Btw. here's a small C# project which compiles just fine (using VS 15.8.8 or MSBuild 15.8.169.51996) , without any warnings or errors. Feel free to use it as a starting point to track down & fix your versioning issue.

.csproj:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net47</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Moq" Version="4.10.0" />
  </ItemGroup>

</Project>

.cs:

using Moq;

public interface IMockable
{
    (bool success, string message) TryGetMessage();
}

class Program
{
    static void Main()
    {
        var (success, message) = Mock.Of<IMockable>().TryGetMessage();
    }
}

Closing as off-topic (versioning conflicts have come to be so frequent on the .NET Framework these days that unfortunately everyone needs to understand and learn how to deal with them), and as a duplicate (like I wrote above, additional NuGet targets are already under consideration — though to be honest net47 is not on the list; net471 or net472, perhaps).

@stakx stakx closed this as completed Nov 7, 2018
@bassettb
Copy link
Author

bassettb commented Nov 7, 2018

That's disappointing. Our solution has 90 projects and uses 30-40 nuget packages. We still use many non-nuget DLLs. But we aren't unique. Not every project out there is created perfectly clean like your example. Many company's projects are slowly migrating from pre-nuget days using Framework to a future goal of using nuget and netstandard. And along the way, they have a lot of challenges with package dependencies and tooling issues. I'm sure there are many other users who, like us, can't use the latest version of moq because of these errors. Ideally, a nuget package has few/no dependencies.
So it's easy to say 'this is Microsoft's problem'. But you could solve it for a lot of people with a very small change in your code and allow wider adoption of your latest version.

@stakx
Copy link
Contributor

stakx commented Nov 8, 2018

Of course not every code base is as pristine as the little example I posted above. I posted it only to demonstrate that the claim, "the current 4.5 target causes major build issues in Framework 4.7 projects" simply doesn't hold true in general. I am suggesting that if things don't work in your case, there must be some other factor involved, and it is important to know what that is before we blindly apply a fix.

I am not going to introduce a net47 target on blind faith that it will magically solve versioning issues for "a lot of people". First, I want to understand what exactly can go wrong. If you can post a small solution that reproduces the issue you're seeing, then I'm happy to look into it.

@stakx stakx reopened this Nov 8, 2018
@stakx stakx changed the title Target Framework 4.7 net45 target causes major build issues in .NET Framework 4.7 projects Nov 8, 2018
@stakx
Copy link
Contributor

stakx commented Nov 8, 2018

@bassettb - I changed Moq such that it no longer needs to depend on System.ValueTuple at all... which appears to be the NuGet dependency that causes you problems. Will this help you?

@stakx stakx closed this as completed Nov 17, 2018
@stakx
Copy link
Contributor

stakx commented Dec 3, 2018

@bassettb - I just pushed Moq 4.10.1 to NuGet. This version no longer depends on System.ValueTuple, and dependencies on System.* NuGet packages have been upgraded to the latest versions. Consider giving it a try.

@devlooped devlooped locked and limited conversation to collaborators Sep 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants