Diego Ribeiro - .NET Developer

Diego Ribeiro

C# | .NET | ASP.NET Core | Azure

© 2024 Diego Ribeiro.

First post


Updating WebForms: CodeDomProviders and Providers.Site Introduction In this post, I’ll walk you through updating the CodeDomProviders in a .NET WebForms project, focusing on the installation and configuration of the Microsoft.CodeDom.Providers.DotNetCompilerPlatform package. This is essential for ensuring compatibility and leveraging the latest features in the .NET ecosystem.

Step-by-Step Guide NuGet Package Installation

First, we need to install or update the Microsoft.CodeDom.Providers.DotNetCompilerPlatform package in your WebForms project. This package includes both Microsoft.CodeDom.Providers.DotNetCompilerPlatform and Microsoft.CodeDom.Providers.DotNetCompilerPlatform.WebSites.

Using the NuGet Package Manager, execute the following commands: Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform.WebSites

Web.config Configuration

Upon installation, the following configuration will be automatically added to your web.config file:

<system.codedom>
  <compilers>
    <compiler extension=".cs" language="c#;cs;csharp" warningLevel="4" compilerOptions="/langversion:7.3 /nowarn:1659;1699;1701;612;618" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    <compiler extension=".vb" language="vb;vbs;visualbasic;vbscript" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008,40000,40008 /define:_MYTYPE=&quot;Web&quot; /optionInfer+" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </compilers>
</system.codedom>

Handling Missing Assembly Errors

If you encounter missing assembly errors after this update, follow these steps:

Wait a few minutes and rebuild the solution to check if the issue resolves itself. If the error persists, try cleaning the solution and reinstalling the packages: Clean the solution in Visual Studio. Close Visual Studio. Reopen Visual Studio and rebuild the project. Reinstalling NuGet Packages

After upgrading the .NET Framework, it’s crucial to update the NuGet packages to be compatible with the new framework. The packages do not retarget automatically, but there’s a simple fix:

Open the Package Manager Console and run: Update-Package -Reinstall

Important: Use this command after pulling from TFS to refresh the BIN folder.

For projects with older packages that are not available on NuGet, manually copy the DLL from the BIN folder and add it to the Source Control.

Reinstalling Packages for a Specific Project

If you need to reinstall packages for a specific project, use the following command: Update-Package -Reinstall -ProjectName Project.Name.Here

This command forces the package manager to reinstall every package in the specified project, ensuring that all references are updated to the correct version.

Conclusion By following these steps, you can ensure that your .NET WebForms project is up-to-date with the latest CodeDomProviders, preventing common issues related to assembly references and package compatibility. This not only enhances the stability of your project but also leverages the latest enhancements in the .NET ecosystem.