添加文件/链接到项目 [英] Adding Files/Links To Projects

查看:36
本文介绍了添加文件/链接到项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我是一个业余爱好者程序员,使用C#和VS2008编写桌面应用程序。


我正在努力采取模块化方法来避免重新 - 发现了

轮,但我发现它有点令人沮丧。例如,我有一个

ListViewEx类(基于ListView),它具有就地编辑和基于列内容的

分类器。它使用自定义列标题和自定义

ListViewItems。反过来,ListViewEx可能还有一个类基础它

等等。


当我设置一个测试应用程序这真的回到了我的家下午尝试

并建立一个新课程,我最后添加了大约30个文件的链接,只需要

进行测试。


我很欣赏我可以把它们编译成一个类库,但是每次使用它们时我会遇到另外一个我需要的属性/函数

更容易从项目中更改源代码并重新编译而不是

必须打开并重新编译六个类库。


做的想法这是为了生活,可能会链接到数百美元而不是数百个文件令人恐惧。


其他人对此有何看法?我很失望没有在C#中找到一个

#include指令。有没有办法可以构建东西,以便我可以链接到目录中的所有文件,而不是链接到目录中的每个单独文件?


我很感激任何想法。


-

Jeff Gaines Damerham Hampshire英国

所有相信心理运动的人都会举手。


I am a hobbyist programmer, using C# and VS2008 and writing desktop apps.

I am trying hard to take a modular approach to avoid re-inventing the
wheel but I''m finding it a bit frustrating. For instance I have a
ListViewEx class (based on a ListView) which has in-place editing and a
sorter based on column content. It uses custom column headers and custom
ListViewItems. In turn the ListViewEx may have a further class base on it
and so on.

It really came home to me when I set up a test app this afternoon to try
and build a new class, I ended up adding links to about 30 files just to
run a test.

I appreciate that I could compile them into a class library but each time
they are used I come across another property/function that I need and it
is much easier to change the source from a project and re-compile than to
have to open and re-compile half a dozen class libraries.

The thought of doing this for a living where there may be links to
hundreds rather that dozens of files is horrifying.

What do other people do about this? I was very disappointed not to find a
#include directive in C#. Is there a way I can structure things so that I
can link to all files in a directory for instance, rather than to each
individual file in the directory?

I would appreciate any thoughts.

--
Jeff Gaines Damerham Hampshire UK
All those who believe in psychokinesis raise my hand.

推荐答案

" Jeff Gaines" < wh ********* @ newsgroups.nospamwrote in message

news:xn **************** @ msnews.microsoft。 com ...
"Jeff Gaines" <wh*********@newsgroups.nospamwrote in message
news:xn****************@msnews.microsoft.com...

我很欣赏我可以把它们编译成一个类库但是每次使用它们时我会遇到另一个属性/我需要的功能和它

更容易从项目中更改源代码并重新编译而不是

必须打开并重新编译六个类库。
I appreciate that I could compile them into a class library but each time
they are used I come across another property/function that I need and it
is much easier to change the source from a project and re-compile than to
have to open and re-compile half a dozen class libraries.



在编写模块之前,您需要考虑模块的组织。

一种特殊的方法,你可以在它更容易(现在为

),并且汇编分区是任意的,不会扩展。


另外,为什么打开并重新启动-compile" ;?创建一个多项目解决方案,在其中的项目之间设置

依赖项(确保你添加_project_

依赖项,而不是_file_依赖项 - 后者是你的时候只需在Browse中选择

..dll,然后使用Ctrl + Shift + B启动构建。 Visual Studio

(或更准确地说,MSBuild)将负责依赖解析,并且
将仅重建需要重建的东西。

You need to think about organization of your modules before you write them.
An ad-hoc approach where you just slap the class where it''s easier (for
now), and assembly partitions are arbitrary, doesn''t scale.

Also, why "open and re-compile"? Create a multi-project solution, set up
dependencies between projects within it (make sure you''re adding _project_
dependencies, not _file_ dependencies - the latter is when you just pick the
..dll in Browse), and just kick off builds with Ctrl+Shift+B. Visual Studio
(or, more precisely, MSBuild) will take care of dependency resolution, and
will rebuild only the stuff that needs rebuilding.


其他人对此有何看法?我很失望没有在C#中找到一个

#include指令。
What do other people do about this? I was very disappointed not to find a
#include directive in C#.



这是我第一次见到有人怀念#include。

鉴于人们正在努力逐步淘汰它现在在C ++中(希望在C ++ 0x之后的下一个TR的

),这是一种奇怪的情绪。


无论如何,你不是需要#include在C#中,因为它没有概念

的标题。

This is the first time I''ve actually seen someone nostalgic for #include.
Given that people are pushing to phase it out in C++ now (hopefully by the
next TR after C++0x), it''s a strange sentiment.

Anyway, you don''t need #include in C#, because it doesn''t have the concept
of headers.


有没有办法可以构建东西所以我可以链接到

目录中的所有文件,而不是链接到

目录中的每个文件?
Is there a way I can structure things so that I can link to all files in a
directory for instance, rather than to each individual file in the
directory?



不,但是为什么不在目录中的所有文件中组装一个程序集,

然后链接到那个?

No, but why not just make an assembly out of all those files in a directory,
and then link to that?


" Jeff Gaines" < wh ********* @ newsgroups.nospamwrote in message

news:xn *************** @ msnews.microsoft.com ...
"Jeff Gaines" <wh*********@newsgroups.nospamwrote in message
news:xn***************@msnews.microsoft.com...

>>在编写模块之前,您需要考虑模块的组织。一种特殊的方法,你只需要把它放在容易的地方(现在),并且程序集分区是任意的,不会扩展。
>>You need to think about organization of your modules before you write
them. An ad-hoc approach where you just slap the class where it''s easier
(for now), and assembly partitions are arbitrary, doesn''t scale.



每个类/控件都位于自己的目录中,并使用我标准化的
目录/命名空间/类命名来保持一致性。


Each class/control sits in its own directory and uses my standardised
directory/namespace/class naming for consistency.



....

....


这可行,每个类都有自己的项目所以我会需要

将这些项目添加到新项目中,并确保依赖项是明确的。我会看一下。
That could work, each class has its own project so I would just need to
add those projects to the new project, and ensure the dependencies are
clear. I will look at that.



请注意,您可以拥有一个包含多个

类的程序集(即项目),其中每个类仍在一个单独的文件夹中(在该项目下

文件夹)。这没有什么不妥,特别是如果这些类在逻辑上相关并且在它们之间有很多依赖关系。

Note that you can have a single assembly (i.e., project) with multiple
classes, where each class is still in a separate folder (under that project
folder). There''s nothing wrong with that, especially if the classes are
logically related and have lots of dependencies between them.


我是更多地考虑21世纪#include pragma。如果我有一个带有十几个相关类的

ListViewEx类,那么

#include主类文件中的那些类会更好。然后,当在另一个项目中使用它时,链接到主类文件只需要


I was thinking more of a 21st century #include pragma. If I have, say, a
ListViewEx class with a dozen or so related classes it would be good to
#include those classes in the main class file. Then it would only be
necessary to link to the main class file when using it in another project.



..NET没有根据类来定义依赖关系,而是根据

程序集来定义依赖关系。对于程序集,你可以完成你所描述的内容,所以

,因为你的依赖关系不会暴露在你班级的公共成员中。

换句话说,如果你有项目/程序集PA中的A类依赖于B类装配PB中的B类,而后者依赖于装配PC中的C类,那么你只需要参考PB
在PA,而不是PC。只有当B级扩展到C级时,或者如果你使用B的公共成员

在其签名中引用C,你才需要引用PC

。 br />

..NET doesn''t define dependencies in terms of classes, but rather in terms of
assemblies. For assemblies, you can do pretty much what you described, so
long as your dependencies are not exposed in public members of your class.
In other words, if you have class A in project/assembly PA depend on class B
in assembly PB, which in turn depends on class C in assembly PC, then you
only need a reference to PB in PA, not to PC. You''ll need a reference to PC
only if class B extends class C, or if you use a public member of B that
references C in its signature.


我可以添加对类文件dll的引用,但是可能需要

为每个类项目运行一个VS的一个实例来改变/更新

蹄可以这么说。可能更容易添加原始项目。
I could add a reference to the class file dll but would then probably need
one instance of VS running for each class project to alter/update on the
hoof so to speak. Probably adding the original projects is easier.



再次,您不需要每个项目的VS实例。您可以根据需要拥有一个

单个解决方案,并且只需要一个

的VS实例来处理该解决方案,它将完全显示

在解决方案资源管理器中包含所有子项目。

Once again, you do not need an instance of VS per project. You can have a
single solution with as many projects as you wish, and you only need one
instance of VS to work with that solution, and it will be entirely displayed
in Solution Explorer with all the child projects.


2008年4月4日消息< OY *** ***********@TK2MSFTNGP06.phx.gblPavel

Minaev写道:
On 04/09/2008 in message <OY**************@TK2MSFTNGP06.phx.gblPavel
Minaev wrote:

> .NET doesn'根据类定义依赖关系,而不是根据程序集定义。对于程序集,只要您的依赖项未在您的
类的公共成员中公开,您就可以完成您所描述的内容。换句话说,如果你在项目/程序集PA中有A类依赖于程序集PB中的B类,而这又取决于程序集中的C类,那么你只需要引用PB in PA,而不是PC。只有当B类扩展到C类时,或者如果你使用B的公共
成员在其签名中引用C,你才需要对PC进行引用。
>.NET doesn''t define dependencies in terms of classes, but rather in terms
of assemblies. For assemblies, you can do pretty much what you described,
so long as your dependencies are not exposed in public members of your
class. In other words, if you have class A in project/assembly PA depend
on class B in assembly PB, which in turn depends on class C in assembly
PC, then you only need a reference to PB in PA, not to PC. You''ll need a
reference to PC only if class B extends class C, or if you use a public
member of B that references C in its signature.



谢谢 - 我刚刚在

内建立了一个包含多个项目的新项目,并且效果很好: - )

Thank you - I have just set up a new project with several projects within
it and that works nicely :-)


>>我可以添加对类文件dll的引用,但可能需要
一个VS运行的实例每个类项目改变/更新蹄可以这么说。可能更容易添加原始项目。
>>I could add a reference to the class file dll but would then probably need
one instance of VS running for each class project to alter/update on the hoof so to speak. Probably adding the original projects is easier.


再次,您不需要每个项目的VS实例。您可以根据需要拥有多个项目的单一解决方案,并且只需要一个VS实例来处理该解决方案,它将完全显示在解决方案资源管理器中所有的儿童项目。


Once again, you do not need an instance of VS per project. You can have a
single solution with as many projects as you wish, and you only need one
instance of VS to work with that solution, and it will be entirely
displayed in Solution Explorer with all the child projects.



是的,我需要习惯它,但它实现了我想要的,谢谢

再次: - )


一个补充问题...


我正在运行XP专业版x64,但通常编译为x86,因为很多

数据库驱动程序只有x86。


类似于上面的策略怎样才能让我在x86和x64之间切换

?每个包含的项目都可以在x86和

x64之间切换,但''main''项目需要引用包含项目产生的类文件(dll),b
这与x86 / x64不同。是否可以通过一种方式将一个项目轻松切换回来,或者更好地拥有一个x86项目和一个x64项目?

/>

我喜欢编译和测试x64,因为它完全是无情的,

不小心使用''int''代替''uint''而且有无处不在的
电脑 - 所以对我来说这是一个很好的训练!


-

Jeff Gaines Damerham Hampshire UK

640k对任何人都应该足够了。

(比尔盖茨,1981)

Yes, I will need to get used to it but it achieves what I want, thank you
again :-)

A supplementary question...

I am running XP Pro x64 but usually compile for x86 as many of the
database drivers are x86 only.

What about a strategy similar to the above that would enable me to switch
between x86 and x64? Each included project can be switched between x86 and
x64 but the ''main'' project needs a reference to the class file (dll) that
the included project produces, which are different for x86/x64. Is it
possible to have a means whereby a project can easily be switched back and
forth or is it better to just have an x86 project and an x64 project?

I like compiling and testing for x64 because it is totally unforgiving,
careless use of an ''int'' instead of ''uint'' and there are pieces of
computer everywhere - so it is a good discipline for me!

--
Jeff Gaines Damerham Hampshire UK
640k ought to be enough for anyone.
(Bill Gates, 1981)


这篇关于添加文件/链接到项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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