转自:http://www.cnblogs.com/luminji/archive/2010/10/21/1857339.html

  1. 什么是程序集
  2. 程序集标识属性
  3. 强名称的程序集
  4. 强名称工作原理
  5. 配置文件
  6. 使用 DEVPATH 查找程序集
  7. 指定要使用的运行库版本
  8. Appconfig和YourSoftexeconfig
 

本章概要:

1:什么是程序集

2:程序集标识属性

3:强名称的程序集

3.1:强名称工作原理

4:配置文件

5:使用 DEVPATH 查找程序集

6:指定要使用的运行库版本

7:App.config和YourSoft.exe.config

1:什么是程序集

程序集是 .NET Framework 应用程序的构造块;程序集构成了部署、版本控制、重复使用、激活范围控制和安全权限的基本单元。程序集是为协同工作而生成的类型和资源的集合,这些类型和资源构成了一个逻辑功能单元。程序集向公共语言运行库提供了解类型实现所需要的信息。

程序集属性是提供程序集相关信息的值。属性分为以下几组信息:

  • 程序集标识属性。

  • 信息性属性。

  • 程序集清单属性。

  • 强名称属性。

2:程序集标识属性

三种属性与强名称(如果适用)一起决定程序集的标识:名称、版本和区域性。这些属性构成程序集的完整名称,并且在代码中引用程序集时需要这些属性。您可以使用属性来设置程序集的版本和区域性。编译器或程序集链接器 (Al.exe) 根据包含程序集清单的文件在创建程序集时设置名称值。

有关程序集属性的更多信息,参看http://msdn.microsoft.com/zh-cn/library/4w8c1y2s(VS.80).aspx

3:强名称的程序集

强名称是由程序集的标识加上公钥和数字签名组成的,其中,程序集的标识包括简单文本名称、版本号和区域性信息(如果提供的话)。它使用对应的私钥从程序集文件中生成。(程序集文件包含程序集清单,其中包含组成程序集的所有文件的名称和哈希。)

具有强名称的程序集只能使用其他具有强名称的程序集的类型。否则将会危及到该具有强名称的程序集的安全。

3.1:强名称工作原理

签名机制
1. 用SN.exe 生成一个key文件, 这个key文件包括一个public key 和一个private key.
2. 用这个key文件签名assembly时, 编译器将用private key签名程序集, 并将public key嵌入manifest中
3. 编译器哈希manifest中所有的assembly内容, 并将此哈希值各自assembly的FileDef Talbe中.
4. 当如上3步处理后, 编译器将哈希PE文件的整个内容(除authenticode signature, 强名称数据, PE头), 然后将此哈希值用private key签名. 得到RSA数字签名.
5. 将此数字签名嵌入到PE文件的CLR头

防修改机制
1. 当签名后的assembly安装到GAC, 系统会哈希PE文件(同签名), 得到哈希值
2. 系统读取PE文件中CLR头中的RSA签名, 并用public key(包含在manifest中)解密
3. 比较第1步得到的哈希值和第2步得到解密值是否一致, 从而判断其是否被修改.

4:配置文件

配置文件是可以按需要更改的 XML 文件。开发人员可以使用配置文件来更改设置,而不必重编译应用程序。管理员可以使用配置文件来设置策略,以便影响应用程序在计算机上运行的方式。

配置文件更多内容查看http://msdn.microsoft.com/zh-cn/library/1xtk877y(VS.90).aspx

5:使用 DEVPATH 查找程序集

开发人员可能想确保他们正在生成的共享程序集能与多个应用程序一起正常使用。在开发周期内开发人员不用频繁地将程序集放在全局程序集缓存中,他们可以创建 DEVPATH 环境变量,让该变量指向程序集的生成输出目录。

例如,假设您正在生成名为 MySharedAssembly 的共享程序集,且输出目录是 C:/MySharedAssembly/Debug。可以将 C:/MySharedAssembly/Debug 置于 DEVPATH 变量中。然后必须在计算机配置文件中指定 <developmentMode> 元素。该元素告诉公共语言运行库使用 DEVPATH 来查找程序集。

共享程序集必须能够由运行库发现。 若要指定用于解析程序集引用的私有目录,请在配置文件中使用 <codeBase> 元素<probing> 元素,如 指定程序集的位置 中所述。 还可以将程序集放在应用程序目录的子目录中。有关更多信息,请参见运行库如何定位程序集

下面的示例说明如何使运行库在由 DEVPATH 环境变量所指定的目录中搜索程序集。

<configuration>
<runtime>
<developmentMode developerInstallation="true"/>
</runtime>
</configuration>

6:指定要使用的运行库版本

<?xml version ="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v1.1.4322" />
</startup>
</configuration>

7:App.config和YourSoft.exe.config

为了更加快速的使用配置信息而不自己写代码实现读写,我们在创建应用程序的时候应该使用App.config。创建完毕后,我们发现App.config的属性是:

以上是创建App.config后的默认设置,不要修改这些属性,编译你的解决方案,会在输出目录中发现生成了一个YourSoft.exe.config(假设你的应用程序名为YourSoft.exe)。下面有几点需要说明:

1:YourSoft.exe.config其实对应的就是你解决方案中的App.config。注意,千万不要以为在输出目录中它也会以App.config存在。

2:如果“复制到输出目录”属性你设置的是“复制”或者“较新则复制”,则App.config会被复制到输出目录。千万不要以为在输出目录中的App.config对应用程序会有任何意义。运行时默认还是会去读YourSoft.exe.config。

3:输出目录中YourSoft.exe.config的值不会自动保持和你解决方案中的App.config内容一致。你需要手动去设置YourSoft.exe.config中的值。

练习:

1.You are creating a strong-named assembly named Asse  mbly1 that will be used in multiple applications.

Assembly1 will be rebuilt frequently during the development cycle. You need to ensure that each time the 
assembly is rebuilt it works correctly with each application that uses it. You need to configure the computer on
which you develop Assembly1 such that each application uses the latest bu  ild of Assembly1. Which two actions
should you perform? (Each correct answer presents part of the solution. Choose two.)
A. Create a DEVPATH environment variable that points to the build output directory for the strong-named       
assembly.
B. Add the following XML element to the machine configuration filE.          
<developmentMode developerInstallation="true"/>

C. Add the following XML element to the machine configuration filE.         
<dependentAssembly>    
<assemblyIdentity name="Assembly1" publicKeyToken="32ab4ba45e0a69a1" language="en-US" 
version="*.*.*.*" />
<publisherPolicy apply="no" />    
</dependentAssembly>
D.  Add the following XML element to the configuration file of each application that uses the strong-named       
assembly:  
<supportedRuntime version="*.*.*.*" /> 
E. Add the following XML element to the configuration file of each application that uses the strong-named   
assembly:    
<dependentAssembly>     
<assemblyIdentity name="Assembly1" publicKeyToken="32ab4ba45e0a69a1" language="en-US" 
version="*.*.*.*" />       
<bindingRedirect newVersion="*.*.*.*"/>    
</dependentAssembly>
Answer: A, B

2.Your company uses an application named Application1 that was compiled by using the .NET Framework
version 1.0. The application currently runs on a shared computer on which the .NET Framework versions 1.0 and     
1.1 are installed.     You need to move the application to a new computer on which the .NET Framework versions 
1.1 and 2.0 are installed. The application is compatible with the .NET Framework 1.1, but it is incompatible with   
the .NET Framework 2.0. You need to ensure that the application will use the .NET  Framework version 1.1 on the 
new computer. What should you do?

A.  Add the following XML element to the application configuration file.       
<configuration>     
<startup>       
<supportedRuntime version="1.1.4322" />      
<startup>   
</configuration>

B. Add the following XML element to the application configuration file.       
<configuration>     
<runtime>       
<assemblyBinding  xmlns="urn:schemas-microsoft-com:asm.v1">         
<dependentAssembly>             
<assemblyIdentity name="Application1" 
publicKeyToken="32ab4ba45e0a69a1"  culture="neutral" />             
<bindingRedirect oldVersion="1.0.3075.0" newVersion="1.1.4322.0"/>           
</dependentAssembly>      
</assemblyBinding>   
</runtime>  
</configuration>
C. Add the following XML element to the machine configuration file.          
<configuration>     
<startup>       
<requiredRuntime version="1.1.4322" />       
<startup>   
</configuration>

D.  Add the following XML element to the machine configuration file.          
<configuration>     
<runtime>       
<assemblyBinding  xmlns="urn:schemas-microsoft-com:asm.v1">   
<dependentAssembly>             
<assemblyIdentity name="Application1" 
publicKeyToken="32ab4ba45e0a69a1"  culture="neutral" />

<bindingRedirect oldVersion="1.0.3075.0" newVersion="1.1.4322.0"/>           
</dependentAssembly>      
</assemblyBinding>   
</runtime>  
</configuration>
Answer: A

程序集、应用程序配置及App.config和YourSoft.exe.config .的更多相关文章

  1. app.config *.exe.config 和*.vshost.exe.config基础学习

    一.问题描述 在使用config文件来保存一些参数,便于下次启动程序时自动加载上次设置的参数的功能时, 碰到个问题,vs2010下调试运行程序始终无法实现config记录上次参数值,而直接运行exe程 ...

  2. C#之app.config、exe.config和vshost.exe.config作用区别

    vshost.exe.config是程序运行时的配置文本 exe.config是程序运行后会复制到vshost.exe.config app.config是在vshost.exe.config和exe ...

  3. Debug目录、Release目录,bin目录、obj目录,vshost.exe.config文件、.exe.config文件分析【C#】

    原文地址:http://blog.csdn.net/itwit/article/details/6803338 今天写程序的时候,需要更改.exe.config文件中的引用的webservice地址, ...

  4. 如何使用DotNet 2.0中的应用程序配置 Settings.settings

    对于桌面应用程序,常常会需要记录一些用户配置信息,早期的做法一般是使用读写INI文件的办法.    对于.NET应用程序,并没有提供直接操作INI文件的类,需要调用Win32API,具体办法可以参考: ...

  5. 使用配置文件(.settings、.config)存储应用程序配置

    原文:使用配置文件(.settings..config)存储应用程序配置 引言 我不知大家早先是如何保存应用程序配置,以备下次打开时使用的,反正我开始学.Net的时候就去研究序列化,以二进制或XML格 ...

  6. C# Setting.settings . 用法 2 使用配置文件(.settings、.config)存储应用程序配置

    引言 我不知大家早先是如何保存应用程序配置,以备下次打开时使用的,反正我开始学.Net的时候就去研究序列化,以二进制或XML格式的序列化来保存应用程序配置.这样每次都要建立单独的配置类,并书写读写配置 ...

  7. PHP 后台程序配置config文件,及form表单上传文件

    一,配置config文件 1获取config.php文件数组, 2获取form 表单提交的值 3保存更新config.php文件,代码如下: $color=$_POST['color']; $back ...

  8. .Net 自定义应用程序配置

    .Net 自定义应用程序配置 引言 几乎所有的应用程序都离不开配置,有时候我们会将配置信息存在数据库中(例如大家可能常会见到名为Config这样的表):更多时候,我们会将配置写在Web.config或 ...

  9. 【.net 深呼吸】自定义应用程序配置节

    实际上,应用程序配置文件 App.config,是由各个节(Configuration Section)组成的,通常,配置节是按功能划分的,比如我们很熟悉的 appSettings.connectio ...

随机推荐

  1. Spring Batch的事务– Part 3: 略过和重试

    原文:https://blog.codecentric.de/en/2012/03/transactions-in-spring-batch-part-3-skip-and-retry/ This i ...

  2. codejam环境熟悉—Minimum Scalar Product

    今天准备熟悉一下codejam的在线编程,为google的笔试做准备,因此按照codejam上对新手的建议,先用了一个简单的题目来弄清楚流程.记录一下需要注意的地方.   1.输入输出 输入输出重定位 ...

  3. http协议要点

    概念: HTTP是Hyper Text Transfer Protocol(超文本传输协议)的缩写.它的发展是万维网协会(World Wide Web Consortium)和Internet工作小组 ...

  4. RESTful API 设计最佳实践(转)

    摘要:目前互联网上充斥着大量的关于RESTful API(为了方便,以后API和RESTful API 一个意思)如何设计的文章,然而却没有一个”万能“的设计标准:如何鉴权?API格式如何?你的API ...

  5. vs常用插件之javsscript插件

    1.JSEnhancements 折叠JS和CSS代码 http://visualstudiogallery.msdn.microsoft.com/0696ad60-1c68-4b2a-9646-4b ...

  6. nginx配置 首页不显示 index.html首页是显示域名

    原状况如下: 访问:www.test.com 敲回车后浏览器中自动跳转致: www.test.com/index.html 公司新需求如下: 访问:www.test.com 敲回车后浏览器中url不变 ...

  7. Altium Designer 6三维元件库建模教程

    一.AD6.9 PCB编辑环境下如何使用STEP模型的方法. 在PCB 封装库中添加对应的3D模型,然后选择update pcb 即可 方法:在PCB library 页面,点击place -- 3d ...

  8. EasyUI Accordion下的Panel面板初始化时全部折叠

    EasyUI Accordion下的Panel面板有一个属性:selected,默认值为:false.初始化时,若设置'selected:true',则面板默认打开,效果如下: <div tit ...

  9. 计数排序详解以及java实现

    前言 我们知道,通过比较两个数大小来进行排序的算法(比如插入排序,合并排序,以及上文提到的快速排序等)的时间复杂度至少是Θ(nlgn),这是因为比较排序对应的决策树的高度至少是Θ(nlgn),所以排序 ...

  10. d3d导致cairo不正常

    最近要把cairo集成到项目中,却发现cairo不能工作了 折腾了两天才找到了原因:cairo的一个trick导致浮点数计算错误: http://blog.163.com/lvan100@yeah/b ...