dotnet / dotnet/project-system
Limited Intellisense for dynamically compiled webforms
- Dominant language
- C#
- Stars
- 1k
- Forks
- 415
- PR merge metrics
- No merged PRs in 30d
Description
**Visual Studio Version**: 15.9.7
**Summary:**
Dynamically compiled webforms have a limited Intellisense available in Visual Studio when using a SDK project. Members declared in `System.Web.UI` classes or depending on it are not available for autocompletion.
**Steps to Reproduce**:
1. Create a new Sdk or Sdk.Web project
2. Switch its target to `net472`, remove .Net Core dependencies if any, set its output to `Library`
3. Add following references:
```xml
```
4. Add the `App_Code` folder (either at the root of the project for Sdk and Sdk.Web projects, or in `wwwroot` in a Sdk.Web project).
5. Add a `PageBase.cs` file in the `App_Code` folder, with following code:
```c#
using System.Web.UI;
namespace SdkWebApplication1.App_Code
{
public class PageBase : Page
{
}
}
```
6. Switch the `PageBase.cs` file Build Action to `Content` (if inside `wwwroot`, it will already be).
7. Add a `Default.aspx` file with following content (either at the root of the project, or in `wwwroot` in a Sdk.Web project):
```xml
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="SdkWebApplication1._Default" %>
```
Note the use of the `CodeFile` attribute instead of the `CodeBehind` one: it is a view for a dynamically compiled webform.
Adjust the namespace in `Inherits` attribute according to the default namespace of your project.
8. Add at the same place a `Default.aspx.cs` file with following content:
```c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace SdkWebApplication1
{
public partial class _Default : App_Code.PageBase
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
```
Adjust the namespaces as required by your case.
9. Switch the `Default.aspx.cs` file Build Action to `Content` (if inside `wwwroot`, it will already be).
**Expected Behavior**:
- At step 6, the inherited `Page` is seen by Intellisense.
- At step 9, the inherited `PageBase` is seen by Intellisense.
**Actual Behavior**:
- At step 6, the inherited `Page` is not seen by Intellisense.
- At step 9, the inherited `PageBase` is not seen by Intellisense.
In both cases, switching the Build Action to `C# compiler` restores Intellisense. But code files inside the `App_Code` folder must not be compiled but deployed to target web server instead. Similarly, *.aspx.cs files meant to be dynamically compiled on the server must not be compiled on build.
Please also note that performing the equivalent steps in an old WebApplication project does work. (There is just a small glitch compared to a web site project (project file less): for the .aspx.cs case to work, its matching view needs to be opened in an editor.)
**User Impact**:
It is very unpractical to try developing with dynamically compiled webforms in a Sdk project.
**Additional notes**:
This issue is reported from [this comment](https://github.com/dotnet/project-system/issues/2670#issuecomment-461852298), as asked [here](https://github.com/dotnet/project-system/issues/2670#issuecomment-464675927) by @davkean.
Contributor guide
Assessment
This issue has not been assessed yet.