Visual Studio 2013 C#:一种解决方案使用另一种解决方案的代码 [英] Visual Studio 2013 C#: one solution consume code of another solution

查看:168
本文介绍了Visual Studio 2013 C#:一种解决方案使用另一种解决方案的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Java背景,正在尝试从C#开始.

I have Java background and am trying to start on C#.

我想在C#中创建一个库,该库将在其他解决方案中使用.在Eclipse中,只需创建一个jar并将其添加到classpath即可.我知道VS2013中的每个项目都会变成一个dll,但是如何使解决方案能够看到这些dll?

I wanna create a lib in C# that will be used in other solutions. In Eclipse it's just a matter of creating a jar and adding it to classpath. I know each project in VS2013 becomes a dll, but how can I make a solution see these dll?

此外,在Eclipse中,我们可以创建一个Web片段项目.它可以包含Servlet,jsp,静态js和css文件,它可以成为war文件,并且可以导入到另一个项目中,并且该文件可以在该项目中使用.

Also, in Eclipse, we can create a Web Fragment Project. It can have Servlets, jsp and static js and css files, it becomes a war file and can be imported into another project and its files be used in that project.

如何在VS2013中做到这一点?我想创建一个包含静态文件,母版页,一些aspx内容,C#dll的解决方案,然后在其他解决方案中全部使用它们.

How can I do that in VS2013? I'd like to create a solution with static files, master page, some aspx stuff, C# dll, and then use them all in other solutions.

是否有任何教程(我用谷歌搜索,但是什么也没找到)来教怎么做?

Is there any tutorial (I googled it but found nothing) teaching how to do it?

推荐答案

您可以根据自己的喜好和范围选择几个选项

You have a few options depending on your preferences and scope

您可以创建类库,该类库可以在您的网站项目中引用.类库是类,接口和值类型的库

You can create Class Library, that can be referenced in your website project. The Class library is a library of classes, interfaces, and value types

您可以将现有/新类库项目添加到您的网站解决方案中,然后直接引用

You can either Add an existing/New Class Library project to your website solution and reference it directly

  1. 您可以通过右键单击
    将项目添加到解决方案中 解决方案(在VS内)->添加->现有项目->并导航至所述
    项目的.csproj文件
  1. You can add the project to your solution by right clicking the
    solution (inside VS) -> Add -> Existing project -> and navigating to said
    project's .csproj file

您可以使用新的/现有的类库项目-进行构建并在您的网站解决方案中引用构建的dll.

You can use a new/existing Class Library Project - build it and reference the built dll in your website solution.

  1. 您可以右键单击您的网站解决方案(在VS内)->添加->新项目->选择类库

完成以上任一操作后->

After you've done one of the above ->

  1. 右键单击要添加引用的项目
  2. 点击添加参考"
  3. 浏览到相关的.dll.

如果您要引用的dll是当前解决方案的一部分(如步骤1中所述)->在按添加引用"后-按解决方案"选项卡,它应该会显示

If the dll you want to reference is part of your current solution (as in step 1) -> after you've pressed "Add Reference" - press the "Solution" Tab and it should show up

添加dll之后. 请记住使用

After you've added the dll. Remember to reference it in your code files with

Using TheReferenceNamespace;

这将允许您像下面这样调用dll内部的函数

which will allow you to call the functions inside you dll like the following

FunctionInsideDll(param);

或者您可以完全限定您的通话资格,如下所示:

or you could fully qualify your calls instead, like the following

TheReferenceNamespace.FunctionInsideDll(param); 

选项2 -共享母版页

如果您只想要可共享"母版页 您可以执行以下操作-(摘自此->

Option 2 - Share MasterPages

if you just want "shareable" masterpages you can do the following - (taken from this -> MSDN article) (for future reference - web archive link - just in case something gets moved)

预编译母版页中使用的代码

如果您担心母版页中的代码对于其他人重复使用它们的页面可见,则可以将母版页的代码预编译到库中.在此库中,您可以包括代码隐藏页以及用户或自定义控件.编译母版页不会删除母版文件或所使用的任何服务器控件的声明性代码,但是您可以编译母版文件以删除母版页所使用的控件或代码隐藏页的代码.

If you are concerned about code in your master pages being visible to others reusing the pages, you can precompile the master pages' code into a library. In this library, you can include code-behind pages as well as user or custom controls. Compiling master pages does not remove the declarative code for the master files or any server controls used, but you can compile the master files to remove the code for controls or code-behind pages used by the master pages.

如果选择将母版页编译到库中,则必须使用可更新"构建选项,该选项允许以后修改标记.此选项由发布网站"对话框中的允许预编译的站点可更新"复选框确定.有关将页面预编译到可重用的库中的更多信息,请参见使用VS 2005构建可重用的ASP.NET用户控件和页面库.

If you choose to compile the master pages into a library, you must use the "updatable" build option that allows for later modification of the markup. This option is determined by the Allow the precompiled site to be updatable check box in the Publish Web Site dialog box. For more information about precompiling pages into a library that can be reused, see Building Re-Usable ASP.NET User Control and Page Libraries with VS 2005.

创建一个模板,并将该模板用于不同的项目 在Visual Studio中-按文件"->导出模板->遵循向导. 导出并导入后(通过向导中的对勾或双击vsix文件),在创建新项目时,它将显示在项目模板下.

Create a template, and use that template for different projects In Visual Studio - Press "File" -> Export Template -> follow the wizard. After it has been exported and you've imported it (either through a checkmark in the wizard or double clicking the vsix file) -it will show up under your project templates when you create a new project.

这篇关于Visual Studio 2013 C#:一种解决方案使用另一种解决方案的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆