英文:
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: "
英文:
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)
{
}
}
}
答案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).
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:
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 = "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).
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:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论