开发者

Create designer.cs file programmatically

开发者 https://www.devze.com 2023-01-01 17:49 出处:网络
Can somebody tell me how to create designer.cs file by using .net code. Basically what i want to do here is that i have a bunch of aspx and ascx files created by previous versions of vs.net that lacks

Can somebody tell me how to create designer.cs file by using .net code. Basically what i want to do here is that i have a bunch of aspx and ascx files created by previous versions of vs.net that lacks designer fi开发者_如何转开发les and now i want to create designer files for those. I can generate empty designer files but what i want is that my code should generate the designer file so that i can remove the extra code from cs files. Any help will be highly appreciated.


You're probably talking about the Web Site vs. Web Project stuff.

Create a new Web Project, import your files, and then right-click on each file and choose "Convert to Web Application". This will generate your designer files.


I needed to create a generator that copies and modifies an existing "template solution" and creates individual .ascx and .ascx.cs files. To let Visual Studio generate the .ascx.designer.cs files, I start it with the new .sln (or .csproj) file and the command line argument

/Command "Project.ConverttoWebApplication" like so:

Process.Start(new ProcessStartInfo
{
    FileName = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe",
    Arguments = string.Format("{0} /Command \"Project.ConverttoWebApplication\"", "NewSolution.sln")
});

This will generate the designer files which may take some seconds, depending on the number of files. Since I did this right now, I am not yet sure whether the command is applied to the whole solution which you might not want to do. I couldn't yet figure out how to programmatically select the desired project, but it works fine for me. Maybe someone else has more informations about that.

0

精彩评论

暂无评论...
验证码 换一张
取 消