Loading the Common Language Runtime (CLR via C#学习笔记)D1部分

来源:互联网 发布:淘宝弹窗怎么关闭 编辑:程序博客网 时间:2024/04/30 22:26

1.Each assembly you build can be either an executable application or a DLL containing a set 
of types for use by an executable application . Of course, the CLR is responsible for man- 
aging the execution of code contained within these assemblies . This means that the  .NET 
Framework must be installed on the host machine . Microsoft has created a redistribution 
package that you can freely ship to install the  .NET Framework on your customers’ machines . 
Some versions of Windows ship with the  .NET Framework already installed .

 

 

每个你编译的集合可以是一个可执行的引用程序或者一个包含了对应用程序有用的类型集合的DLL.当然,CLR会对包含在这些编译集合中的代码的执行负责,这种情况意味着.NET Framework必须安装在主机上。

Microsoft 已经发布了这么个附加安装包,你可以免费直接安装.NET Framework 在你客户的机器上。一些版本的Windows 直接就附带已经安装好的.NET Framework

 

 

You can tell if the .NET Framework has been installed by looking for the MSCorEE.dll file in the %SystemRoot%/System32 directory. The existence of this file tells you that the .NET Framework is installed. However, several versions of the .NET Framework can be installed on a single machine simultaneously . If you want to determine exactly which versions of the .NET Framework are installed, examine the subkeys under the following registry key:

HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/NET Framework Setup/NDP

翻译:你可以说只要去%SystemRoot%/System32 directory中看一下是否有MSCorEE.dll文件从而判断.NETFramework装上没。这个文件的存在告诉你.NETFramework已经装上了。不过,有很多种版本的.NETFramework 可以同时安装到一台机器上。如果你想确切地知道你装的.NETFramework的版本,按照下面的注册表操作检查一下键值即可:

HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/NET Framework Setup/NDP

 

 

The .NET Framework SDK includes a command-line utility called CLRVer .exe that shows all of the CLR versions installed on a machine . This utility can also show which version of the CLR is

being used by processes currently running on the machine by using the –all switch or passing

the ID of the process you are interested in .

翻译:.NETFramework SDK 包含一个叫做CLR.exe的命令行程序,它能显示所有安装在一个机器上的CLR版本。当你在机器上用ID号开启感兴趣的程序的时候这个程序也能显示

当前相应的进程所用的CLR版本。

 

 

Before we start looking at how the CLR loads, we need to spend a moment discussing 32-bit

and 64-bit versions of Windows . If your assembly files contain only type-safe managed code,

you are writing code that should work on both 32-bit and 64-bit versions of Windows . No

source code changes are required for your code to run on either version of Windows . In fact,

the resulting EXE/DLL file produced by the compiler will run on 32-bit Windows as well as the

x64 and IA64 versions of 64-bit Windows! In other words, the one file will run on any machine

that has a version of the  .NET Framework installed on it .

翻译:在我们开始查看CLR时怎么运行的时候,我们需要花费一些时间去讨论一下32位和64位版本的Windows。如果你的编译文件只包含安全类型的受控代码,你要写的可以在32位和64位版本的Windows上运行的代码。那么不需要源代码的改变就可以在这两个版本中任意一个上运行。事实上,编译器产生的EXE/DLL文件将在32位或者64Windows上都可以运行!换句话说,这个文件可以在装了任何版本的.NETFramework的任何机器上运行。

 

On extremely rare occasions, developers want to write code that works only on a specific ver-

sion of Windows . Developers might do this when using unsafe code or when interoperating

with unmanaged code that is targeted to a specific CPU architecture . To aid these developers,

the C# compiler offers a /platform command-line switch . This switch allows you to specify

whether the resulting assembly can run on x86 machines running 32-bit Windows versions

only, x64 machines running 64-bit Windows only, or Intel Itanium machines running 64-bit

Windows only. If you don’t specify a platform, the default is anycpu, which indicates that

the resulting assembly can run on any version of Windows . Users of Visual Studio can set a

project’s target platform by displaying the project’s property pages, clicking the Build tab,

and then selecting an option in the Platform Target list .

翻译:在一种很少见的时候,开发者想仅仅为Windows特别的版本写代码,开发者也许

会在使用不安全代码或者与针对某些特别的CPU结构的非托管代码接触的时候这么做。为了帮助这些开发者C#提供了一个/平台 命令行转换器。这种转换器允许你判别:生成的编译文件只能在配置32Windows系列的x86机器、配置64Windows系列的x64机器上运行吗?,在配置64WindowsIntel  Itanium 机器呢?。如果你不去区分一个平台,默认的就是anycpu,这表明编译代码能在任何版本的Windows上运行,Visual Studio的使用者们能在工程的属性页上,通过点击“建立”标签并在Platform Target (目标平台)的下拉菜单中选择一个选项这个操作来选择工程的目标平台。

 

原创粉丝点击