umbraco / Umbraco-CMS

Umbraco is a free and open source .NET content management system helping you deliver delightful digital experiences.
https://umbraco.com
MIT License
4.42k stars 2.67k forks source link

Remove Microsoft.Net.Compilers dependency #6495

Closed ronaldbarendse closed 4 years ago

ronaldbarendse commented 4 years ago

The Umbraco 8 NuGet package includes a dependency on Microsoft.Net.Compilers (>= 2.10.0 && < 2.999999): https://github.com/umbraco/Umbraco-CMS/blob/178b1ccf40aa67815be77698a259b5db31ab9013/build/NuSpecs/UmbracoCms.nuspec#L33

As commented earlier (https://github.com/umbraco/Umbraco-CMS/issues/4493#issuecomment-489080794), this is not required as Microsoft.CodeDom.Providers.DotNetCompilerPlatform (>= 2.0.0) already includes the compiler binaries (for dynamic compilation of views): https://github.com/aspnet/RoslynCodeDomProvider#version-200.

Installing Microsoft.Net.Compilers replaces the built-in compiler that's used when building the project and because of the version range, it's not possible to update this to the latest version to make use of new C# features. It's also slower than using the compiler Visual Studio ships with and version 2.10.0 is actually the same as the minimum required VS version for local development: https://our.umbraco.com/Documentation/Getting-Started/Setup/Requirements/#local-development.

Reproduction

Bug summary

Can't use the latest C# features, as the compiler gets replaced by an out-of-date version because it's included as a NuGet dependency.

Workaround

It's possible to forcefully remove the package PM> Uninstall-Package Microsoft.Net.Compilers -Force (gives errors when updating Umbraco), remove the build-target from the project file (needs to be repeated after updating the package) or move code to a seperate library. This should however not be required...

nul800sebastiaan commented 4 years ago

Sure thing!

umbrabot commented 4 years ago

Hi @ronaldbarendse,

We're writing to let you know that we've added the Up For Grabs label to your issue. We feel that this issue is ideal to flag for a community member to work on it. Once flagged here, folk looking for issues to work on will know to look at yours. Of course, please feel free work on this yourself ;-). If there are any changes to this status, we'll be sure to let you know.

For more information about issues and states, have a look at this blog post

Thanks muchly, from your friendly PR team bot :-)

ronaldbarendse commented 4 years ago

PR is created, I'm going for that hacktoberfest/contrib-2019 label 😉

SteveVaneeckhout commented 4 years ago

What are the consequences when there is no compiler anymore for the Modelbuilder?

ronaldbarendse commented 4 years ago

It just uses the default compiler (from your development environment), just like it did on Umbraco 7...

SteveVaneeckhout commented 4 years ago

But you can use the modelbuilder on a webserver with no development environment installed.

ronaldbarendse commented 4 years ago

You can still use Models Builder, as that doesn't depend on this package (and if it did, it would require this as its own dependency anyway - Models Builder is still an external package)...

Besides, to run ASP.NET websites on a webserver, you also need to install additional services and features, including the default compiler that comes with the .NET Framework: https://docs.microsoft.com/en-us/iis/application-frameworks/scenario-build-an-aspnet-website-on-iis/configuring-step-1-install-iis-and-asp-net-modules.

nul800sebastiaan commented 4 years ago

Fixed in https://github.com/umbraco/Umbraco-CMS/pull/6501

ronaldbarendse commented 4 years ago

@nul800sebastiaan We might need an upgrade warning/instruction for this, because it doesn't automatically remove the installed package, but effectively removes the version restriction.

So after updating Umbraco to 8.4.0, Microsoft.Net.Compilers could be updated to the latest version (3.4.0 at the time of writing) and that threw the following error while installing, corrupting the project file (by not removing the imported build target for the old version):

The expression ""Controllers\DownloadsController.cs".GetPathsOfAllDirectoriesAbove()" cannot be evaluated. Method 'System.String.GetPathsOfAllDirectoriesAbove' not found. ...\packages\Microsoft.Net.Compilers.3.4.0\tools\Microsoft.Managed.Core.targets

This is only an issue when upgrading Umbraco and updating this package (new projects won't have this package installed). As this package isn't required, it can be removed after upgrading:

Uninstall-Package Microsoft.Net.Compilers

Or the version restriction can be added to the projects packages.config file:

<package id="Microsoft.Net.Compilers" version="2.10.0" targetFramework="net472" developmentDependency="true" allowedVersions="[2.10.0,2.999999)" />
nul800sebastiaan commented 4 years ago

Yeah, I see this as one of those things that will be good for future people installing Umbraco, I had no illusions that it would magically fix existing projects without a manual step. People who really need this will surely find your comment on here.

ajaysadyaldoeacc commented 2 years ago

This error usually comes when you upgrade the below libraries by nuget

Microsoft.CodeDom.Providers.DotNetCompilerPlatform

Microsoft.Net.Compilers

Guys, If your project is not loading due to this error. just go to that project location by explorer and delete the obj folder manually.

Then right-click on the project and RELOAD AGAIN.

ajaysadyaldoeacc commented 2 years ago

This error usually comes when you upgrade the below libraries by nuget

Microsoft.CodeDom.Providers.DotNetCompilerPlatform

Microsoft.Net.Compilers

Guys, If your project is not loading due to this error. just go to that project location by explorer and delete the obj folder manually.

Then right-click on the project and RELOAD AGAIN.