返回信息流比如,我们有一个windowFormApp项目,还有class1、class2、class3等类库项目。
每个项目的Properties/AssemblyInfo.cs文件中,记录了以下信息:
-----------------------------------------------------
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ClassLibrary2")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ClassLibrary2")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("4977084f-5eca-4b7d-bee3-25289d09690b")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
------------------------------------------------------
显然,我们可以在每个项目中的AssemblyInfo.cs修改公司、程序版本等信息,但是如果工程繁多,要在每个项目中都做这样的修改,显然吃力不讨好。
那么,我们可以建立一个叫SolutionInfo.cs文件,把AssemblyInfo.cs中的公共信息,剪切到SolutionInfo.cs文件中,如下
------------------------------------------------------
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.0.0")]
------------------------------------------------------
这样,只要修改这个文件就可以了。
但是,每个工程中都需要有这个文件才行吧?
在各个工程中建立solutionInfo.cs,并拷贝最初的solutionInfo.cs的内容也未尝不可,但是比较理想的方式是:
只建立一个solutionInfo.cs,修改这个solutionInfo.cs,其他工程的solutionInfo.cs也跟着修改。
实现方式如下:
1、在windowFormApp项目中,建立一个solutionInfo.cs,保存上述的信息。
2、在class1、class2、class3等项目中,点击鼠标右键"添加已存在的文件",即添加windowFormApp项目中的solutionInfo.cs文件。添加的时候,如下图所示方式添加。
这时,添加的是一个link,而不是一个文件,只需要在windowFormApp项目中solutionInfo.cs中修改相关信息就行了。
这是一条镜像帖。来源:北邮人论坛 / dot-net / #2084同步于 2010/7/7
该镜像源已超过 30 天没有更新,可能在源站已被删除。
dotNET机器人发帖
抛砖引玉之 多project开发,如果控制统一的版本号、公司版权信
ahomer
2010/7/7镜像同步4 回复
订阅后,新回复会通过你的通知中心匿名送达。
4 条回复
【 在 ahomer 的大作中提到: 】
: 欢迎大家分享 .NET开发中的点滴知识~~
: --
: ╭════╮╭════╮
: ...................
我来相应号召~~
Assembly Attribute 是 .net 开发的一大利器!
特别在做各种Code Injection时,通过Assembly Attribute可以用来获取Assembly的具体信息。
举个典型场景:
应用程序的Plug-In系统,Host App在加载Plug-in时,往往都需要读取Plug-in的版本,规范,名字,描述,签名,证书等等一系列数据,而且这种时候,可以写一个Attribute,然后把Attribute Usage设置为Assembly专用,然后Attribute中附上这些信息。
这样Host App可以通过简单Reflect一下Plug-in的Assembly就能获取到所有相关的信息。
求贴代码~ 例子~
设置attribute为assembly,是比较简单的,但是怎么把你所说的关联处理起来?
Host-app加载Plug-in,可以先定义公共的接口,所有Plug-in Assembly实现这个接口,然后
把Plug-in的 Assembly name,实现公共接口的class name等信息记录到一个文件,比如存到一个数据表中,然后Host-app根据这个数据表,加载实现了公共接口的Plug-in类,转成统一接口类型,实现Plug-in加载,也是可以的。
【 在 TimNew 的大作中提到: 】
: : 欢迎大家分享 .NET开发中的点滴知识~~
: : --
: : ╭════╮╭════╮
: ...................
【 在 ahomer 的大作中提到: 】
: 求贴代码~ 例子~
: 设置attribute为assembly,是比较简单的,但是怎么把你所说的关联处理起来?
: Host-app加载Plug-in,可以先定义公共的接口,所有Plug-in Assembly实现这个接口,然后
: ...................
我得清理一下代码~
公司一个Project的Prototype~
我得把Credential的东东去掉