CLR Via CSharp读书笔记(2):生成、打包、部署以及管理应用程序及类型

本文介绍了如何使用C#创建一个多文件程序库,包括定义常用类型和罕见类型,并通过不同方式构建多文件库。展示了如何在应用程序中使用该库,并提供了详细的版本信息设置。

Ch02-1-SimpleProgram.cs

public sealed class Program {
   public static void Main() {
      System.Console.WriteLine("Hi");
   }
}

Ch02-2-Minimum MSCorLib.cs

// This project is a DLL that has the "Do not reference mscorlib.dll" option turned on

namespace System {
   public class  Object { }
   public struct Byte { }
   public struct SByte { }
   public struct Int16 { }
   public struct Int32 { }
   public struct Int64 { }
   public struct UInt16 { }
   public struct UInt32 { }
   public struct UInt64 { }
   public struct IntPtr { }
   public struct UIntPtr { }
   public struct Single { }
   public struct Double { }
   public struct Char { }
   public struct Boolean { }
   public class  Type { }
   public class  ValueType { }
   public class  Enum { }
   public struct Void { }
   public class  Array { }
   public class  Exception { }
   public class  ParamArrayAttribute { }
   public struct RuntimeTypeHandle { }
   public struct RuntimeFieldHandle { }
   public class  Attribute { }
   public class  Delegate { }
   public class  MulticastDelegate { }
   public class  String { }
   public interface IDisposable { }
   public enum AttributeTargets { Assembly = 1, Class = 4, }

   [AttributeUsage(AttributeTargets.Class, Inherited = true)]
   public sealed class AttributeUsageAttribute : Attribute {
       public AttributeUsageAttribute(AttributeTargets validOn) { }
       public bool AllowMultiple { get; set; }
       public bool Inherited { get; set; }
   }
}

namespace System.Runtime.InteropServices {
   public class OutAttribute { }
}

namespace System.Runtime.Versioning {
   [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)]
   public sealed class TargetFrameworkAttribute : Attribute {
       public TargetFrameworkAttribute(String frameworkName) { }
       public String FrameworkDisplayName { get; set; }
   }
 }

namespace System.Reflection {
   public class DefaultMemberAttribute { }
}

namespace System.Collections {
   public interface IEnumerable { }
   public interface IEnumerator { }
}

Ch02-3-FUT.cs

using System;

public sealed class AFrequentlyUsedType {
   public AFrequentlyUsedType() {
      Console.WriteLine("A frequently used type was constructed.");
   }
}

Ch02-3-RUT.cs

using System;

public sealed class ARarelyUsedType {
   public ARarelyUsedType() {
      Console.WriteLine("A rarely used type was constructed.");
   }
}

Ch02-3-AssemblyVersionInfo.cs

using System.Reflection;

// FileDescription version information:
[assembly: AssemblyTitle("JeffTypes.dll")]

// Comments version information:
[assembly: AssemblyDescription("This assembly contains Jeff's types")]

// CompanyName version information:
[assembly: AssemblyCompany("Wintellect")]

// ProductName version information:
[assembly: AssemblyProduct("Wintellect (R) Jeff's Type Library")]

// LegalCopyright version information:
[assembly: AssemblyCopyright("Copyright (c) Wintellect 2010")]

// LegalTrademarks version information:
[assembly:AssemblyTrademark("JeffTypes is a registered trademark of Wintellect")]

// AssemblyVersion version information:
[assembly: AssemblyVersion("3.0.0.0")]

// FILEVERSION/FileVersion version information:
[assembly: AssemblyFileVersion("1.0.0.0")]

// PRODUCTVERSION/ProductVersion version information:
[assembly: AssemblyInformationalVersion("2.0.0.0")]

// Set the Language field (discussed later in the "Culture" section)
[assembly:AssemblyCulture("")]

Ch02-3-BuildMultiFileLibrary.bat

@echo off
Rem %1="$(DevEnvDir)", %2="$(SolutionDir)", %3="$(OutDir)"

rem Set all the VS environment variables
pushd %1
call ..\Tools\VSVars32.bat
popd

rem Change to the solution directory
cd %2

REM There are two ways to build this multi-file assembly
REM The line below picks one of those ways
Goto Way1

:Way1
csc /t:module  /debug:full /out:Ch02-3-RUT.netmodule Ch02-3-RUT.cs
csc /t:library /debug:full /out:Ch02-3-MultiFileLibrary.dll /addmodule:Ch02-3-RUT.netmodule Ch02-3-FUT.cs Ch02-3-AssemblyVersionInfo.cs
md %3
move /Y Ch02-3-RUT.netmodule %3
move /Y Ch02-3-RUT.pdb %3
move /Y Ch02-3-MultiFileLibrary.dll %3
move /Y Ch02-3-MultiFileLibrary.pdb %3
goto Exit

:Way2
csc /t:module /debug:full /out:Ch02-3-RUT.netmodule Ch02-3-RUT.cs
csc /t:module /debug:full /out:Ch02-3-FUT.netmodule Ch02-3-FUT.cs Ch02-3-AssemblyVersionInfo.cs
al  /out:Ch02-3-MultiFileLibrary.dll /t:library Ch02-3-RUT.netmodule Ch02-3-FUT.netmodule
md %3
move /Y Ch02-3-RUT.netmodule %3
move /Y Ch02-3-RUT.pdb %3
move /Y Ch02-3-FUT.netmodule %3
move /Y Ch02-3-FUT.pdb %3
move /Y Ch02-3-MultiFileLibrary.dll %3
move /Y Ch02-3-MultiFileLibrary.pdb %3
goto Exit

:Exit

Ch02-4-AppUsingMultiFileLibrary.cs

using System;

public static class AppUsingMultiFileLibrary {
   public static void Main() {
      new AFrequentlyUsedType();
      new ARarelyUsedType();
   }
}

 

转载于:https://www.cnblogs.com/thlzhf/archive/2012/11/25/2787249.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值