简体   繁体   English

将C#用户控件添加到现有的asp.net vb.net项目

[英]add c# user control to existing asp.net vb.net project

I've got an existing asp.net project written in vb.net. 我有一个用vb.net编写的现有asp.net项目。 Another person has written a user control in c#. 另一个人用c#编写了一个用户控件。

Could you please let me know the steps for adding that C# user control to the vb.net app? 您能否让我知道将C#用户控件添加到vb.net应用程序的步骤?

I've tried copying them to the folder and using "Add existing item", however it doesn't compile the code behind at all. 我尝试将它们复制到文件夹并使用“添加现有项”,但是它根本不编译后面的代码。

Thanks, Fidel 谢谢菲德尔

用c#创建一个新的asp.net用户控件库项目,向该项目添加C#用户控件,然后在您的Visual Basic项目中添加对该库的引用,就是这样;)

You could use this tool to add the control to the VS toolbox. 您可以使用工具将控件添加到VS工具箱。

An example of usage (choose either /vs2005 or /vs2008 depending on your VS version): 用法示例(根据VS版本选择/ vs2005或/ vs2008):

TOOLBOX.EXE [/vs2005] [/vs2008] /installdesktop assembly tabname

Just wanted to add another way to accomplish this, as I was just about to ask a question regarding this topic and figured out the solution. 只是想添加另一种方法来实现此目的,因为我正要提出有关此主题的问题并找出解决方案。

If you truly need to bring over the raw user control files into a new project, you will find simply adding them via 'Add -> Existing Item...' will make each file come into the solution independently and not structure them properly in Solution Explorer. 如果您确实需要将原始用户控制文件转移到新项目中,则可以通过“添加->现有项目...”添加它们,这会使每个文件独立进入解决方案,而在解决方案中无法正确构建它们资源管理器。

The trick is to open up the (2) associated user control code files outside of VS.NET prior to adding to your solution and modify thier namespace to be that of your new project. 诀窍是添加到解决方案之前在VS.NET外部打开(2)关联的用户控制代码文件, 然后将其命名空间修改为新项目的命名空间。 So if in the old project your namespace was: 因此,如果在旧项目中您的命名空间为:

MyOldProject.CustomControls

...you will want to rename in the .cs and .Designer.cs to the following: ...您将要在.cs.Designer.cs重命名为以下内​​容:

MyNewProject.CustomControls

Then when you go back into VS.NET add add all of the existing items, they will be in their proper arrangement as follows: 然后,当您回到VS.NET时,添加所有现有项,它们将按照以下方式进行适当排列:

MyControl.cs MyControl.cs
--> MyControl.Designer.cs -> MyControl.Designer.cs
--> MyControl.resx -> MyControl.resx
--> MyControl -> MyControl

The C# control will need to be in a seperate dll. C#控件将需要在单独的dll中。 You can then add a reference to this dll in your vb project. 然后,您可以在vb项目中添加对此dll的引用。 Then register the control in the page directive or web.config, like normal. 然后像往常一样在page指令或web.config中注册控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM