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

Remove Microsoft.Net.Compilers dependency #6495

Closed
ronaldbarendse opened this issue Oct 1, 2019 · 12 comments · Fixed by #6501
Closed

Remove Microsoft.Net.Compilers dependency #6495

ronaldbarendse opened this issue Oct 1, 2019 · 12 comments · Fixed by #6501

Comments

@ronaldbarendse
Copy link
Contributor

The Umbraco 8 NuGet package includes a dependency on Microsoft.Net.Compilers (>= 2.10.0 && < 2.999999):

<dependency id="Microsoft.Net.Compilers" version="[2.10.0,2.999999)" />

As commented earlier (#4493 (comment)), 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
Copy link
Member

Sure thing!

@umbrabot
Copy link

umbrabot commented Oct 1, 2019

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
Copy link
Contributor Author

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

@SteveVaneeckhout
Copy link
Contributor

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

@ronaldbarendse
Copy link
Contributor Author

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

@SteveVaneeckhout
Copy link
Contributor

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

@ronaldbarendse
Copy link
Contributor Author

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
Copy link
Member

Fixed in #6501

@ronaldbarendse
Copy link
Contributor Author

@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
Copy link
Member

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
Copy link

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.

1 similar comment
@ajaysadyaldoeacc
Copy link

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.

@umbraco umbraco locked and limited conversation to collaborators Oct 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants