T4MVC / R4MVC

R4MVC is a Roslyn code generator for ASP.NET Core MVC apps that creates strongly typed helpers that eliminate the use of literal strings in many places
Apache License 2.0
157 stars 48 forks source link

Properly support framework multi-targeting #66

Open artiomchi opened 7 years ago

artiomchi commented 7 years ago

At the moment, this is either ignored (best case), or no code will be identified by the compiler in the first place (worst case!)

When R4Mvc.Tools loads a web project, we have to identify the target framework of that project, and possibly configure MSBuild to pick a desired framework. Need to test that with multi targeted projects, as well as identifying the differences based on which framework comes first in that list.

artiomchi commented 6 years ago

So, there's no perfect solution for this just yet, but I just came up with a pretty decent workaround that will let people use R4Mvc in their multi-targeted projects!

To do this, you'll have to change your csproj file to only use one framework when the project is built by R4Mvc using a build property, like follows:

<PropertyGroup Condition="$(IsR4MvcBuild) == ''">
  <TargetFrameworks>net462;netcoreapp2.1</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition="$(IsR4MvcBuild) != ''">
  <TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

Your regular builds won't be affected, but R4Mvc will be able to handle it just fine.

Can't come up with a proper fix yet, as MSBuild seems to have some issues that doesn't make it easy to load multi-targeted projects (with dependencies that target other frameworks). I'll still keep an eye on this, and hopefully will eventually find a proper solution to this.

Buildalyzer is actually a great option as well, but at the moment it doesn't work either (thanks to a different issue with MSBuild!)

Until then, I'll leave this issue open. If anyone has an even better solution to this - help is always greatly appreciated!

artiomchi commented 6 years ago

Moving this to v1 Backlog, since we now have a workaround in place, which makes the current library usable in multi targeted projects