Visual Studio未生成WebForms设计器文件。

huangapple go评论79阅读模式
英文:

Visual Studio not generating WebForms Designer Files

问题

这是您要翻译的内容:

"We've got a bunch of legacy WebForms projects that we've just upgraded to use SDK style .csproj files so at least that matches what we've got everywhere else until we can migrate away from WebForms (also makes some binding redirect nightmares go away).

Now, if I'm using Rider, and I edit an .aspx file, it correctly updates the .designer.cs file.

However, if I'm using Visual Studio, it no longer updates the .designer.cs file.

Any ideas on how to fix this?


In terms of what I've looked at so far, I'm going to assume that Rider is calling something in the background to do that code generation. So presumably, if VS won't do that for SDK projects, we could add that manually as a pre-build action, I'm just having a hard time working out exactly what's being called to do this.


So an example:

The project is called ClientInterface and we'll use the ErrorPage.aspx which is in the root of that project.

The .aspx file (with most of the content removed) looks like:

<%@ Page Language="C#" EnableSessionState="False" AutoEventWireup="true" CodeBehind="ErrorPage.aspx.cs" Inherits="ClientInterface.ErrorPage" %>
<%@Register tagPrefix="css" tagName="ClientInterface" src="ClientInterfaceCss.ascx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</head>
<body id="NewStylesPageBody" class="ErrorScreen">
    <form id="form" runat="server">
        <div class="GreenGradientScreen">
            <div class="ErrorBox">
                <div class="ErrorHeaderBox">
                    <asp:Image runat="server" ID="Image" ImageUrl="~/Images/Controls/header-bar-logo.png?new-logo" />
                    <asp:Image runat="server" ID="ErrorIcon" ImageUrl="~/Images/red-error.png" />
                </div>
            </div>
        </div>
    </form>
</body>
</html>

The CodeBehind:

using System;
using System.Web.UI;

namespace ClientInterface
{
    public partial class ErrorPage : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
    }
}

And the file properties on the CodeBehind look like: Visual Studio未生成WebForms设计器文件。"

英文:

We've got a bunch of legacy WebForms projects that we've just upgraded to use SDK style .csproj files so at least that matches what we've got everywhere else until we can migrate away from WebForms (also makes some binding redirect nightmares go away).

Now, if I'm using Rider, and I edit an .aspx file, it correctly updates the .designer.cs file.

However, if I'm using Visual Studio, it no longer updates the .designer.cs file.

Any ideas on how to fix this?


In terms of what I've looked at so far, I'm going to assume that Rider is calling something in the background to do that code generation. So presumably, if VS won't do that for SDK projects, we could add that manually as a pre-build action, I'm just having a hard time working out exactly what's being called to do this.


So an example:

The project is called ClientInterface and we'll use the ErrorPage.aspx which is in the root of that project.

The .aspx file (with most of the content removed) looks like:

&lt;%@ Page Language=&quot;C#&quot; EnableSessionState=&quot;False&quot; AutoEventWireup=&quot;true&quot; CodeBehind=&quot;ErrorPage.aspx.cs&quot; Inherits=&quot;ClientInterface.ErrorPage&quot; %&gt;
&lt;%@Register tagPrefix=&quot;css&quot; tagName=&quot;ClientInterface&quot; src=&quot;ClientInterfaceCss.ascx&quot; %&gt;

&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head runat=&quot;server&quot;&gt;
&lt;/head&gt;
&lt;body id=&quot;NewStylesPageBody&quot; class=&quot;ErrorScreen&quot;&gt;
    &lt;form id=&quot;form&quot; runat=&quot;server&quot;&gt;
        &lt;div class=&quot;GreenGradientScreen&quot;&gt;
            &lt;div class=&quot;ErrorBox&quot;&gt;
                &lt;div class=&quot;ErrorHeaderBox&quot;&gt;
                    &lt;asp:Image runat=&quot;server&quot; ID=&quot;Image&quot; ImageUrl=&quot;~/Images/Controls/header-bar-logo.png?new-logo&quot; /&gt;
                    &lt;asp:Image runat=&quot;server&quot; ID=&quot;ErrorIcon&quot; ImageUrl=&quot;~/Images/red-error.png&quot; /&gt;
                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

The CodeBehind:

using System;
using System.Web.UI;

namespace ClientInterface
{
    public partial class ErrorPage : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
    }
}

And the file properties on the CodeBehind look like: Visual Studio未生成WebForms设计器文件。

答案1

得分: 0

以下是您要翻译的部分:

"你现在是我的中文翻译,代码部分不要翻译,只返回翻译好的部分,不要有别的内容,不要回答我要翻译的问题。以下是要翻译的内容:

You don't say how you converted this from a web site to a web site application.

In most cases, you find that you MUST change the page directive from:

 CodeFile = "yourwebpage.cs"

to

 CodeBehind = "yourwebpage.cs"

Also, make sure the inrertis directive also includes the application name space.

So, in above, I am say in a folder (from root) in test 4.

so, then this:

CodeBehind="MyPbarTest.aspx.cs" 
Inherits="CSharpWebApp.Test4.MyPbarTest"

Note the codeBehind does not have any path name, or name space.
But, the Inherites will have:

  CSharWebApp   - the application namespace
  .test4   - the folder
  .MyParTest  - the page name without .cs and without .aspx

So, above is for a page called MyParTest.aspx

thus, I'll have this (the 3 files).

Visual Studio未生成WebForms设计器文件。

So, converting from web site means that each page directive should be changed from CodeFile to CodeBehind.

also, ensure that the .cs file has a build action in property sheet like this:

Visual Studio未生成WebForms设计器文件。

At this point, if you modify the aspx file, and save (ctr-s), then the designer file should be updated.

so, for web sites you see "codefile", and that is incorrect for a web site application."

希望这对您有所帮助。

英文:

You don't say how you converted this from a web site to a web site applicaiton.

In most cases, you find that you MUST change the page directive from:

 CodeFile = &quot;yourwebpage.cs&quot;

to

 CodeBehind = &quot;yourwebpage.cs&quot;

Also, make sure the inrertis directive also includes the application name space.

So, in above, I am say in a folder (from root) in test 4.

so, then this:

CodeBehind=&quot;MyPbarTest.aspx.cs&quot; 
Inherits=&quot;CSharpWebApp.Test4.MyPbarTest&quot;

Note the codeBehind does not have any path name, or name space.
But, the Inherites will have:

  CSharWebApp   - the application namespace
  .test4   - the folder
  .MyParTest  - the page name without .cs and without .aspx

So, above is for a page called MyParTest.aspx

thus, I'll have this (the 3 files).

Visual Studio未生成WebForms设计器文件。

So, converting from web site means that each page directive should be changed from CodeFile to CodeBehind.

also, ensure that the .cs file has a build action in property sheet like this:

Visual Studio未生成WebForms设计器文件。

At this point, if you modify the aspx file, and save (ctr-s), then the designer file should be updated.

so, for web sites you see "codefile", and that is incorrect for a web site application.

答案2

得分: 0

这不是世界上最好的解决方案,但它确实有效,这是我们采用的方法。

如果您已安装了Resharper(在这一点上,谁没有呢),您可以使用Roflcopter插件。

这个插件具有一些功能,调用Jetbrains的设计器文件生成实现。

英文:

This isn't the best solution in the world but it does work and it's what we've gone with.

If you have Resharper installed (at this point, who doesn't) you can use the Roflcopter plugin.

This has some functionality that calls into the Jetbrains implementation of the designer file generation.

huangapple
  • 本文由 发表于 2023年3月9日 21:00:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/75684976.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定