C#:使一个文件可从一个项目编辑,但将其包含在两个项目中
我目前有一个解决方案,其中使用了多个 C# 项目中的某个类,一些是 Silverlight,一些是常规项目。出于兼容性原因,我无法为这些实用程序类创建单个项目。起初,我通过将类库项目设为 silverlight 来解决这个问题,以便所有其他项目都可以引用它。
然而,我遇到了另一个问题,导致无法使用 Silverlight 项目作为类库。因此,我采取了制作两个独立的类库项目的方式:一个是 Silverlight,一个是常规项目。在 C++ 中,可以将一个项目文件添加到两个项目,而磁盘上只有一个物理文件。我注意到在 C# 中,将文件添加到第二个项目时它会自动创建副本。我通过一个构建事件解决了这个问题,该事件在构建 Silverlight 项目时将文件从常规库复制到 Silverlight 库。
这一切都有效,所以从技术上来说问题已经解决了。然而,它对于我的口味来说太复杂了。此外,其他不知道我的解决方案的程序员可能会开始编辑依赖(Silverlight)文件,并得到意想不到的结果。
所以我的问题是,您知道有什么好的理由可以正确解决这两个问题吗?你会如何解决它?
I've currently got a solution where a certain class is used from several C# projects, some Silverlight, some regular. For compatibility reasons I cannot create a single project for these utility classes. At first I solved the problem by making the class library project a silverlight one, so that it could be referenced by all other projects.
However, I ran into another problem that made it impossible to use a Silverlight project as the class library. So I resorted to making two separate class library projects: one Silverlight, one regular. In C++ it's possible to add a project file to two projects, while only having one physical file on disk. I noticed that in C#, it automatically makes a copy when adding the file to a second project. I solved this with a build event that copies the file from the regular library to the Silverlight one when the Silverlight project is built.
This all works, so technically the problem is solved. However, it's gotten too convoluted for my taste. Also, other programmers who are unaware of my solution might start to edit the dependent (Silverlight) file, and get unexpected results.
So my question is, do you know of any good reasons to solve these two issues properly? How would you solve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您需要磁盘上的 1 个文件,则在将文件添加到项目时不要使用标准“添加”,而是单击对话框中文件旁边的箭头并选择“添加为链接”,但这并不妨碍对其进行编辑(你必须研究那里的其他选项,我不知道任何)
If you need 1 file on disk do not use the standard "Add" when adding the file to your project but click on the arrow next to it in the dialog and select "Add as link", however this does not prevent it from being edited (you'll have to look into other options there, I'm not aware of any)
我认为您正在谈论链接。看看这里:
http://support.microsoft.com/kb/306234
希望这有帮助。
I think you are talking about linking. Have a look here:
http://support.microsoft.com/kb/306234
Hope this helps.
将文件放在一个项目中,然后在您想要的其他项目中添加现有项目,选择文件并看到对话框中的“添加”按钮有一个小箭头,选择
添加为链接
从那里你就准备好了。 :)have the file in one project then in the other projects where you want to have it as well do Add Existing Item, select the file and see the Add button in the dialog has a small arrow, select
Add as Link
from there and you are set. :)