
C#将Culture分为的Neutral Culture 和 Specific Culture,
微软推荐使用 SpecificCulture(其实还有一类Invariant Culture微软不推荐使用,仅仅是周期较短的演示系统开发时推荐使用)
当我们看到 en-US,es-ES等表示culture的名称时,可以这样进行识别
横线前面的部分称为Neutral Culture,它是“与某种语言关联但不与国家/地区关联的区域性”的含义
横线后面的部分称为Specific Culture ,它就是和某个地区国家有关的了
通常采用这种写法,因此我们能很容易分辨这两种Culture,如:fr-FR
只有一种特殊情况,就是中文,它的关系是这样的
zh-CHS Chinese (Simplified) , Neutral
zh-CN Chinese - China
zh-CHT Chinese (Traditional) , Neutral
zh-TW Chinese - Taiwan
zh-HK Chinese - Hong Kong SAR
zh-MO Chinese - Macao SAR
zh-SG Chinese - Singapore
可以看到,主要就是 Neutral通常应该是两位的,但这里的Neutral:zh-CHS和zh-CHT有6位,这是比较容易混淆的,而真正的Specific Culture是:zh-CN,zh-TW ,zh-HK,zh-MO,zh-SG 。
指出这个特例也是本文的目的。
·您是指如何将程序集签名吗?
A:您可以使用 snexe 生成一个密钥文件,然后在项目属性里指定要使用的密钥文件。
·您是指如何通过一个已经签名的程序集的 PublicKeyToken 来导出密钥文件?
A:这个不大可能吧?
·如何取得 PublicKeyToken?
可以参加示例代码:
using System;
using SystemReflection;
using SystemThreading;
using SystemIO;
using SystemGlobalization;
using SystemReflectionEmit;
using SystemConfigurationAssemblies;
using SystemText;
public class AssemblyName_CodeBase
{
public static void MakeAssembly(AssemblyName myAssemblyName, string fileName)
{
// Get the assembly builder from the application domain associated with the current thread
AssemblyBuilder myAssemblyBuilder = ThreadGetDomain()DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccessRunAndSave);
// Create a dynamic module in the assembly
ModuleBuilder myModuleBuilder = myAssemblyBuilderDefineDynamicModule("MyModule", fileName);
// Create a type in the module
TypeBuilder myTypeBuilder = myModuleBuilderDefineType("MyType");
// Create a method called 'Main'
MethodBuilder myMethodBuilder = myTypeBuilderDefineMethod("Main", MethodAttributesPublic | MethodAttributesHideBySig |
MethodAttributesStatic, typeof(void), null);
// Get the Intermediate Language generator for the method
ILGenerator myILGenerator = myMethodBuilderGetILGenerator();
// Use the utility method to generate the IL instructions that print a string to the console
myILGeneratorEmitWriteLine("Hello World!");
// Generate the 'ret' IL instruction
myILGeneratorEmit(OpCodesRet);
// End the creation of the type
myTypeBuilderCreateType();
// Set the method with name 'Main' as the entry point in the assembly
myAssemblyBuilderSetEntryPoint(myMethodBuilder);
myAssemblyBuilderSave(fileName);
}
public static void Main()
{
// Create a dynamic assembly with name 'MyAssembly' and build version '1002001'
AssemblyName myAssemblyName = new AssemblyName();
// Set the codebase to the physical directory were the assembly resides
myAssemblyNameCodeBase = StringConcat("file:///", DirectoryGetCurrentDirectory());
// Set the culture information of the assembly to 'English-American'
myAssemblyNameCultureInfo = new CultureInfo("en-US");
// Set the hash algoritm to 'SHA1'
myAssemblyNameHashAlgorithm = AssemblyHashAlgorithmSHA1;
myAssemblyNameVersionCompatibility = AssemblyVersionCompatibilitySameProcess;
myAssemblyNameFlags = AssemblyNameFlagsPublicKey;
// Provide this assembly with a strong name
myAssemblyNameKeyPair = new StrongNameKeyPair(FileOpen("KeyPairsnk", FileModeOpen, FileAccessRead));
myAssemblyNameName = "MyAssembly";
myAssemblyNameVersion = new Version("1002001");
MakeAssembly(myAssemblyName, "MyAssemblyexe");
// Get the assemblies loaded in the current application domain
Assembly[] myAssemblies = ThreadGetDomain()GetAssemblies();
// Get the dynamic assembly named 'MyAssembly'
Assembly myAssembly = null;
for(int i = 0; i < myAssembliesLength; i++)
if(StringCompare(myAssemblies[i]GetName()Name, "MyAssembly") == 0)
myAssembly = myAssemblies[i];
// Display the full assembly information to the console
if(myAssembly != null)
{
ConsoleWriteLine("\nDisplaying the full assembly name\n");
ConsoleWriteLine(myAssemblyGetName()FullName);
ConsoleWriteLine("\nDisplaying the public key\n");
byte []pk;
pk = myAssemblyGetName()GetPublicKey();
for (int i=0;i<pkGetLength(0);i++)
ConsoleWrite ("{0:x}", pk[i]);
ConsoleWriteLine();
ConsoleWriteLine("\nDisplaying the public key token\n");
byte []pt;
pt = myAssemblyGetName()GetPublicKeyToken(); // 此行取得 PublicKeyToken
for (int i=0;i<ptGetLength(0);i++)
ConsoleWrite ("{0:x}", pt[i]);
}
}
}
如果你安装了Vsnet那么该程序就在你的
<盘符>\Program Files\Microsoft Visual Studio NET 2003\SDK\v11\Bin
或者
系统根目录<系统根目录>\MicrosoftNET\SDK\v11\Bin 里面
Visual Studio NET 工具->Visual Studio NET 2003 命令提示
再输入SN
命令行里面输入snexe
密钥的文件路径一般使用相对路径
AssemblyInfocs中已经有说明,下面是引用的AssemblyInfocs中的一些说明
// 注意:
// () 如果未指定密钥,则程序集不会被签名。
// () KeyName 是指已经安装在计算机上的
// 加密服务提供程序(CSP)中的密钥。KeyFile 是指包含
// 密钥的文件。
// () 如果 KeyFile 和 KeyName 值都已指定,则
// 发生下列处理:
// (1) 如果在 CSP 中可以找到 KeyName,则使用该密钥。
// (2) 如果 KeyName 不存在而 KeyFile 存在,则
// KeyFile 中的密钥安装到 CSP 中并且使用该密钥。
// () 要创建 KeyFile,可以使用 snexe(强名称)实用工具。
// 在指定 KeyFile 时,KeyFile 的位置应该相对于
// 项目输出目录,即
// %Project Directory%\obj\<configuration>。例如,如果 KeyFile 位于
// 该项目目录,应将 AssemblyKeyFile
// 属性指定为 [assembly: AssemblyKeyFile("\\\\mykeysnk")]
// () “延迟签名”是一个高级选项 - 有关它的更多信息,请参阅 Microsoft NET Framework
// 文档。
mastercam2022安装程序集组件时出错通过以下方法解决。
1、点选开始菜单后的设置。
2、在d出的菜单中选择更新和安全。
3、选择恢复中的立即重启。
4、重启后选择疑难解答。
5、选择高级启动中的启动设置,点击重启按钮。
6、按提示输入7禁用驱动程序强制签名后,重新安装驱动即可。
将资源文件放到设备上的某个目录中。
创建一个文本文件,其中每行列出一个文件及其路径。
以 gac 扩展名将该文本文件保存到设备的 Windows 目录中。
程序集文件可以是 ANSI 或 UTF-8 编码文件,但不支持其他 Unicode 编码。
以下是一个 MyDllsgac 示例,它列出了三个要安装到全局程序集缓存中的文件:
\Program Files\MyApp\MyDll1Dll
\Program Files\MyApp\MyDll2Dll
\Program Files\MyApp\MyDll3Dll
下次运行应用程序时,NET Compact Framework 会将您在 gac 文本文件中列出的文件移动到全局程序集缓存中。这些文件必须用强名称签名。目前不支持延迟签名。对 gac 文本文件的任何更改将导致以下结果:
如果从 Windows 目录中删除 gac 文本文件,则下次运行应用程序时将从全局程序集缓存中移除该文本文件中列出的文件。
如果更新 gac 文本文件,则 NET Compact Framework 将在全局程序集缓存中相应地更新该文件。
不能使用同一名称加载各个程序集。您必须更改 DLL 的名称,或在 DLL 具有强名称时,可将其放入全局程序集缓存中并使用具有完整强名称的Load方法。通过在桌面上打开命令行和使用
以上就是关于程序集引用里面的“Culture=neutral”是什么意思全部的内容,包括:程序集引用里面的“Culture=neutral”是什么意思、命令行sn.exe 无效、mastercam2022安装程序集组件时出错等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)