AssemblyBuilder.DefineVersionInfoResource メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > AssemblyBuilder.DefineVersionInfoResource メソッドの意味・解説 

AssemblyBuilder.DefineVersionInfoResource メソッド

このアセンブリのアンマネージ バージョン情報リソース定義します
オーバーロードの一覧オーバーロードの一覧

名前 説明
AssemblyBuilder.DefineVersionInfoResource () アセンブリの AssemblyName オブジェクトおよびアセンブリカスタム属性指定され情報使用して、アンマネージ バージョン情報リソース定義します
AssemblyBuilder.DefineVersionInfoResource (String, String, String, String, String) 指定され仕様使用して、このアセンブリのアンマネージ バージョン情報リソース定義します
参照参照

関連項目

AssemblyBuilder クラス
AssemblyBuilder メンバ
System.Reflection.Emit 名前空間

AssemblyBuilder.DefineVersionInfoResource メソッド (String, String, String, String, String)

指定され仕様使用して、このアセンブリのアンマネージ バージョン情報リソース定義します

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub DefineVersionInfoResource ( _
    product As String, _
    productVersion As String, _
    company As String, _
    copyright As String, _
    trademark As String _
)
Dim instance As AssemblyBuilder
Dim product As String
Dim productVersion As String
Dim company As String
Dim copyright As String
Dim trademark As String

instance.DefineVersionInfoResource(product, productVersion, company, copyright, trademark)
public void DefineVersionInfoResource (
    string product,
    string productVersion,
    string company,
    string copyright,
    string trademark
)
public:
void DefineVersionInfoResource (
    String^ product, 
    String^ productVersion, 
    String^ company, 
    String^ copyright, 
    String^ trademark
)
public void DefineVersionInfoResource (
    String product, 
    String productVersion, 
    String company, 
    String copyright, 
    String trademark
)
public function DefineVersionInfoResource (
    product : String, 
    productVersion : String, 
    company : String, 
    copyright : String, 
    trademark : String
)

パラメータ

product

このアセンブリと共に配布する製品の名前。

productVersion

このアセンブリと共に配布する製品バージョン

company

このアセンブリ作成した会社名

copyright

このアセンブリ適用されるすべての著作権表記商標、および登録商標記述します。これには著作権表記全文著作権商標などを示す記号著作権取得日、商標番号などが含まれます。英語では、この文字列は "Copyright Microsoft Corp. 1990-2001" という書式なります

trademark

このアセンブリ適用されるすべての商標および登録商標記述します。これには著作権表記全文著作権商標などを示す記号商標番号などが含まれます。英語では、この文字列は "Windows is a trademark of Microsoft Corporation" という書式なります

例外例外
例外種類条件

ArgumentException

アンマネージ バージョン情報リソースが既に定義されています。

または

アンマネージ バージョン情報大きすぎて、永続化できません。

SecurityException

呼び出し元に必要なアクセス許可がありません。

解説解説
使用例使用例

次の例は、DefineVersionInfoResource使用法示してます。

Imports System
Imports System.Reflection
Imports System.Reflection.Emit

Module Example

   Sub Main()

      Dim assemName As New
 AssemblyName()
      assemName.Name = "EmittedAssembly"

      ' Create a dynamic assembly in the current application domain
,
      ' specifying that the assembly is to be saved.
      '
      Dim myAssembly As AssemblyBuilder = _
         AppDomain.CurrentDomain.DefineDynamicAssembly(assemName, _
            AssemblyBuilderAccess.Save)


      ' To apply an attribute to a dynamic assembly, first get the 
      ' attribute type. The AssemblyFileVersionAttribute sets the 
      ' File Version field on the Version tab of the Windows file
      ' properties dialog.
      '
      Dim attributeType As Type = GetType(AssemblyFileVersionAttribute)

      ' To identify the constructor, use an array of types representing
      ' the constructor's parameter types. This ctor takes a string.
      '
      Dim ctorParameters() As Type = { GetType(String)
 }

      ' Get the constructor for the attribute.
      '
      Dim ctor As ConstructorInfo = _
                         attributeType.GetConstructor(ctorParameters)

      ' Pass the constructor and an array of arguments (in this case
,
      ' an array containing a single string) to the 
      ' CustomAttributeBuilder constructor.
      '
      Dim ctorArgs() As Object
 = { "2.0.3033.0" }
      Dim attribute As New
 CustomAttributeBuilder(ctor, ctorArgs)

      ' Finally, apply the attribute to the assembly.
      '
      myAssembly.SetCustomAttribute(attribute)


      ' The pattern described above is used to create and apply
      ' several more attributes. As it happens, all these attributes
      ' have a constructor that takes a string, so the same ctorArgs
      ' variable works for all of them.
      

      ' The AssemblyTitleAttribute sets the Description field on
      ' the General tab and the Version tab of the Windows file 
      ' properties dialog.
      '
      attributeType = GetType(AssemblyTitleAttribute)
      ctor = attributeType.GetConstructor(ctorParameters)
      ctorArgs = New Object() { "The
 Application Title" }
      attribute = New CustomAttributeBuilder(ctor, ctorArgs)
      myAssembly.SetCustomAttribute(attribute)

      ' The AssemblyCopyrightAttribute sets the Copyright field on
      ' the Version tab.
      '
      attributeType = GetType(AssemblyCopyrightAttribute)
      ctor = attributeType.GetConstructor(ctorParameters)
      ctorArgs = New Object() { "
 My Example Company 1991-2005" }
      attribute = New CustomAttributeBuilder(ctor, ctorArgs)
      myAssembly.SetCustomAttribute(attribute)

      ' The AssemblyDescriptionAttribute sets the Comment item.
      '
      attributeType = GetType(AssemblyDescriptionAttribute)
      ctor = attributeType.GetConstructor(ctorParameters)
      attribute = New CustomAttributeBuilder(ctor, _
         New Object() { "This
 is a comment." })
      myAssembly.SetCustomAttribute(attribute)

      ' The AssemblyCompanyAttribute sets the Company item.
      '
      attributeType = GetType(AssemblyCompanyAttribute)
      ctor = attributeType.GetConstructor(ctorParameters)
      attribute = New CustomAttributeBuilder(ctor, _
         New Object() { "My
 Example Company" })
      myAssembly.SetCustomAttribute(attribute)

      ' The AssemblyProductAttribute sets the Product Name item.
      '
      attributeType = GetType(AssemblyProductAttribute)
      ctor = attributeType.GetConstructor(ctorParameters)
      attribute = New CustomAttributeBuilder(ctor, _
         New Object() { "My
 Product Name" })
      myAssembly.SetCustomAttribute(attribute)


      ' Define the assembly's only module. For a single-file assembly
,
      ' the module name is the assembly name.
      '
      Dim myModule As ModuleBuilder = _
         myAssembly.DefineDynamicModule(assemName.Name, _
            assemName.Name & ".exe")

      ' No types or methods are created for this example.


      ' Define the unmanaged version information resource, which
      ' contains the attribute informaion applied earlier, and save
      ' the assembly. Use the Windows Explorer to examine the properties
      ' of the .exe file.
      '
      myAssembly.DefineVersionInfoResource()
      myAssembly.Save(assemName.Name & ".exe")

   End Sub 
End Module
using System;
using System.Reflection;
using System.Reflection.Emit;

class Example
{
   public static void Main()
   {
      AssemblyName assemName = new AssemblyName();
      assemName.Name = "EmittedAssembly";

      // Create a dynamic assembly in the current application domain
,
      // specifying that the assembly is to be saved.
      //
      AssemblyBuilder myAssembly = 
         AppDomain.CurrentDomain.DefineDynamicAssembly(assemName, 
            AssemblyBuilderAccess.Save);


      // To apply an attribute to a dynamic assembly, first get the
 
      // attribute type. The AssemblyFileVersionAttribute sets the 
      // File Version field on the Version tab of the Windows file
      // properties dialog.
      //
      Type attributeType = typeof(AssemblyFileVersionAttribute);

      // To identify the constructor, use an array of types representing
      // the constructor's parameter types. This ctor takes a string.
      //
      Type[] ctorParameters = { typeof(string) };

      // Get the constructor for the attribute.
      //
      ConstructorInfo ctor = attributeType.GetConstructor(ctorParameters);

      // Pass the constructor and an array of arguments (in this case
,
      // an array containing a single string) to the 
      // CustomAttributeBuilder constructor.
      //
      object[] ctorArgs = { "2.0.3033.0" };
      CustomAttributeBuilder attribute = 
         new CustomAttributeBuilder(ctor, ctorArgs);

      // Finally, apply the attribute to the assembly.
      //
      myAssembly.SetCustomAttribute(attribute);


      // The pattern described above is used to create and apply
      // several more attributes. As it happens, all these attributes
      // have a constructor that takes a string, so the same ctorArgs
      // variable works for all of them.
      

      // The AssemblyTitleAttribute sets the Description field on
      // the General tab and the Version tab of the Windows file 
      // properties dialog.
      //
      attributeType = typeof(AssemblyTitleAttribute);
      ctor = attributeType.GetConstructor(ctorParameters);
      ctorArgs = new object[] { "The Application Title"
 };
      attribute = new CustomAttributeBuilder(ctor, ctorArgs);
      myAssembly.SetCustomAttribute(attribute);

      // The AssemblyCopyrightAttribute sets the Copyright field on
      // the Version tab.
      //
      attributeType = typeof(AssemblyCopyrightAttribute);
      ctor = attributeType.GetConstructor(ctorParameters);
      ctorArgs = new object[] { " My Example Company 1991-2005"
 };
      attribute = new CustomAttributeBuilder(ctor, ctorArgs);
      myAssembly.SetCustomAttribute(attribute);

      // The AssemblyDescriptionAttribute sets the Comment item.
      //
      attributeType = typeof(AssemblyDescriptionAttribute);
      ctor = attributeType.GetConstructor(ctorParameters);
      attribute = new CustomAttributeBuilder(ctor, 
         new object[] { "This is a comment." });
      myAssembly.SetCustomAttribute(attribute);

      // The AssemblyCompanyAttribute sets the Company item.
      //
      attributeType = typeof(AssemblyCompanyAttribute);
      ctor = attributeType.GetConstructor(ctorParameters);
      attribute = new CustomAttributeBuilder(ctor, 
         new object[] { "My Example Company" });
      myAssembly.SetCustomAttribute(attribute);

      // The AssemblyProductAttribute sets the Product Name item.
      //
      attributeType = typeof(AssemblyProductAttribute);
      ctor = attributeType.GetConstructor(ctorParameters);
      attribute = new CustomAttributeBuilder(ctor, 
         new object[] { "My Product Name" });
      myAssembly.SetCustomAttribute(attribute);


      // Define the assembly's only module. For a single-file assembly
,
      // the module name is the assembly name.
      //
      ModuleBuilder myModule = 
         myAssembly.DefineDynamicModule(assemName.Name, 
            assemName.Name + ".exe");

      // No types or methods are created for this example.


      // Define the unmanaged version information resource, which
      // contains the attribute informaion applied earlier, and save
      // the assembly. Use the Windows Explorer to examine the properties
      // of the .exe file.
      //
      myAssembly.DefineVersionInfoResource();
      myAssembly.Save(assemName.Name + ".exe");

   }
}
using namespace System;
using namespace System::Reflection;
using namespace System::Reflection::Emit;


/*
// Create the callee transient dynamic assembly.
static Type^ CreateAssembly( AppDomain^ myDomain )
{
   AssemblyName^ myAssemblyName = gcnew AssemblyName;
   myAssemblyName->Name = "MyEmittedAssembly";
   AssemblyBuilder^ myAssembly = myDomain->DefineDynamicAssembly( myAssemblyName,
 AssemblyBuilderAccess::Save );
   
   // Set Company Attribute to the assembly.
   Type^ companyAttribute = AssemblyCompanyAttribute::typeid;
   array<Type^>^types1 = {String::typeid};
   ConstructorInfo^ myConstructorInfo1 = companyAttribute->GetConstructor( types1
 );
   array<Object^>^obj1 = {"Microsoft Corporation"};
   CustomAttributeBuilder^ attributeBuilder1 = gcnew CustomAttributeBuilder( myConstructorInfo1,obj1
 );
   myAssembly->SetCustomAttribute( attributeBuilder1 );
   
   // Set Copyright Attribute to the assembly.
   Type^ copyrightAttribute = AssemblyCopyrightAttribute::typeid;
   array<Type^>^types2 = {String::typeid};
   ConstructorInfo^ myConstructorInfo2 = copyrightAttribute->GetConstructor( types2
 );
   array<Object^>^obj2 = {"@Copyright Microsoft Corp. 1990-2001"};
   CustomAttributeBuilder^ attributeBuilder2 = gcnew CustomAttributeBuilder( myConstructorInfo2,obj2
 );
   myAssembly->SetCustomAttribute( attributeBuilder2 );
   ModuleBuilder^ myModule = myAssembly->DefineDynamicModule( "EmittedModule",
 "EmittedModule.mod" );
   
   // Define a public class named S"HelloWorld" in the assembly.
   TypeBuilder^ helloWorldClass = myModule->DefineType( "HelloWorld",
 TypeAttributes::Public );
   
   // Define the Display method.
   MethodBuilder^ myMethod = helloWorldClass->DefineMethod( "Display",
 MethodAttributes::Public, String::typeid, nullptr );
   
   // Generate IL for GetGreeting.
   ILGenerator^ methodIL = myMethod->GetILGenerator();
   methodIL->Emit( OpCodes::Ldstr, "Display method get
 called." );
   methodIL->Emit( OpCodes::Ret );
   
   // Returns the type HelloWorld.
   return (helloWorldClass->CreateType());
}
*/

int main()
{
   AssemblyName^ assemName = gcnew AssemblyName();
   assemName->Name = "EmittedAssembly";

   // Create a dynamic assembly in the current application domain,
   // specifying that the assembly is to be saved.
   //
   AssemblyBuilder^ myAssembly = 
      AppDomain::CurrentDomain->DefineDynamicAssembly(assemName, 
         AssemblyBuilderAccess::Save);


   // To apply an attribute to a dynamic assembly, first get the 
   // attribute type. The AssemblyFileVersionAttribute sets the 
   // File Version field on the Version tab of the Windows file
   // properties dialog.
   //
   Type^ attributeType = AssemblyFileVersionAttribute::typeid;

   // To identify the constructor, use an array of types representing
   // the constructor's parameter types. This ctor takes a string.
   //
   array<Type^>^ ctorParameters = { String::typeid };

   // Get the constructor for the attribute.
   //
   ConstructorInfo^ ctor = attributeType->GetConstructor(ctorParameters);

   // Pass the constructor and an array of arguments (in this case,
   // an array containing a single string) to the 
   // CustomAttributeBuilder constructor.
   //
   array<Object^>^ ctorArgs = { "2.0.3033.0" };
   CustomAttributeBuilder^ attribute = 
      gcnew CustomAttributeBuilder(ctor, ctorArgs);

   // Finally, apply the attribute to the assembly.
   //
   myAssembly->SetCustomAttribute(attribute);


   // The pattern described above is used to create and apply
   // several more attributes. As it happens, all these attributes
   // have a constructor that takes a string, so the same ctorArgs
   // variable works for all of them.
    

   // The AssemblyTitleAttribute sets the Description field on
   // the General tab and the Version tab of the Windows file 
   // properties dialog.
   //
   attributeType = AssemblyTitleAttribute::typeid;
   ctor = attributeType->GetConstructor(ctorParameters);
   ctorArgs = gcnew array<Object^> { "The Application Title" };
   attribute = gcnew CustomAttributeBuilder(ctor, ctorArgs);
   myAssembly->SetCustomAttribute(attribute);

   // The AssemblyCopyrightAttribute sets the Copyright field on
   // the Version tab.
   //
   attributeType = AssemblyCopyrightAttribute::typeid;
   ctor = attributeType->GetConstructor(ctorParameters);
   ctorArgs = gcnew array<Object^> { " My Example Company 1991-2005"
 };
   attribute = gcnew CustomAttributeBuilder(ctor, ctorArgs);
   myAssembly->SetCustomAttribute(attribute);

   // The AssemblyDescriptionAttribute sets the Comment item.
   //
   attributeType = AssemblyDescriptionAttribute::typeid;
   ctor = attributeType->GetConstructor(ctorParameters);
   attribute = gcnew CustomAttributeBuilder(ctor, 
      gcnew array<Object^> { "This is a comment." });
   myAssembly->SetCustomAttribute(attribute);

   // The AssemblyCompanyAttribute sets the Company item.
   //
   attributeType = AssemblyCompanyAttribute::typeid;
   ctor = attributeType->GetConstructor(ctorParameters);
   attribute = gcnew CustomAttributeBuilder(ctor, 
      gcnew array<Object^> { "My Example Company" });
   myAssembly->SetCustomAttribute(attribute);

   // The AssemblyProductAttribute sets the Product Name item.
   //
   attributeType = AssemblyProductAttribute::typeid;
   ctor = attributeType->GetConstructor(ctorParameters);
   attribute = gcnew CustomAttributeBuilder(ctor, 
      gcnew array<Object^> { "My Product Name" });
   myAssembly->SetCustomAttribute(attribute);


   // Define the assembly's only module. For a single-file assembly
,
   // the module name is the assembly name.
   //
   ModuleBuilder^ myModule = 
      myAssembly->DefineDynamicModule(assemName->Name, 
         assemName->Name + ".exe");

   // No types or methods are created for this example.


   // Define the unmanaged version information resource, which
   // contains the attribute informaion applied earlier, and save
   // the assembly. Use the Windows Explorer to examine the properties
   // of the .exe file.
   //
   myAssembly->DefineVersionInfoResource();
   myAssembly->Save(assemName->Name + ".exe");
}
import System.*;
import System.Threading.*;
import System.Reflection.*;
import System.Reflection.Emit.*;
import System.Resources.*;

public class MyEmitTest
{
    public static void main(String[]
 args)
    {
        AssemblyBuilder myAssembly = (AssemblyBuilder)(CreateAssembly(
            System.Threading.Thread.GetDomain()).get_Assembly());
        IResourceWriter myResourceWriter = 
            myAssembly.DefineResource("myResourceFile", 
            "A sample Resource File", "MyResourceFile.resources");

        myResourceWriter.AddResource("AddResource test", "Test resource
 added");

        // Define unmanaged version information resources.
        myAssembly.DefineVersionInfoResource();
        myAssembly.Save("MyEmittedAssembly.dll");
    } //main

    // Create the callee transient dynamic assembly.
    private static Type CreateAssembly(AppDomain
 myDomain) 
    {
        AssemblyName myAssemblyName =  new AssemblyName();
        myAssemblyName.set_Name("MyEmittedAssembly");
        AssemblyBuilder myAssembly = myDomain.DefineDynamicAssembly(
            myAssemblyName, AssemblyBuilderAccess.Save);

        // Set Company Attribute to the assembly.
        Type companyAttribute = AssemblyCompanyAttribute.class.ToType();
        ConstructorInfo myConstructorInfo1 = companyAttribute.GetConstructor(
            new Type[]{String.class.ToType()});
        CustomAttributeBuilder attributeBuilder1 =  
            new CustomAttributeBuilder(myConstructorInfo1, 
            new Object[]{"Microsoft Corporation"});
        myAssembly.SetCustomAttribute(attributeBuilder1);

        // Set Copyright Attribute to the assembly.
        Type copyrightAttribute = AssemblyCopyrightAttribute.class.ToType();
        ConstructorInfo myConstructorInfo2 = copyrightAttribute.GetConstructor(
            new Type[]{String.class.ToType()});
        CustomAttributeBuilder attributeBuilder2 = 
            new CustomAttributeBuilder(myConstructorInfo2, 
            new Object[]{"@Copyright Microsoft Corp. 1990-2001"});
        myAssembly.SetCustomAttribute(attributeBuilder2);

        ModuleBuilder myModule = myAssembly.DefineDynamicModule("EmittedModule"
,
            "EmittedModule.mod");

        // Define a public class named "HelloWorld" in the
 assembly.
        TypeBuilder helloWorldClass = myModule.DefineType("HelloWorld",
 
            TypeAttributes.Public);

        // Define the Display method.
        MethodBuilder myMethod = helloWorldClass.DefineMethod("Display",
 
            MethodAttributes.Public, String.class.ToType(), null);

        // Generate IL for GetGreeting.
        ILGenerator methodIL = myMethod.GetILGenerator();
        methodIL.Emit(OpCodes.Ldstr, "Display method get
 called.");
        methodIL.Emit(OpCodes.Ret);

        // Returns the type HelloWorld.
        return helloWorldClass.CreateType();
    } //CreateAssembly
} //MyEmitTest
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
AssemblyBuilder クラス
AssemblyBuilder メンバ
System.Reflection.Emit 名前空間

AssemblyBuilder.DefineVersionInfoResource メソッド ()

アセンブリの AssemblyName オブジェクトおよびアセンブリカスタム属性指定され情報使用して、アンマネージ バージョン情報リソース定義します

名前空間: System.Reflection.Emit
アセンブリ: mscorlib (mscorlib.dll 内)
構文構文

Public Sub DefineVersionInfoResource
Dim instance As AssemblyBuilder

instance.DefineVersionInfoResource
public void DefineVersionInfoResource ()
public:
void DefineVersionInfoResource ()
public void DefineVersionInfoResource ()
public function DefineVersionInfoResource ()
例外例外
例外種類条件

ArgumentException

アンマネージ バージョン情報リソースが既に定義されています。

または

アンマネージ バージョン情報大きすぎて、永続化できません。

SecurityException

呼び出し元に必要なアクセス許可がありません。

解説解説

アセンブリは、1 つのアンマネージ リソースとしか関連付けることができません。DefineVersionInfoResource または DefineUnmanagedResource を呼び出した後で、再びいずれかメソッド呼び出すと、System.ArgumentException がスローさます。複数のアンマネージ リソースは、Microsoft ResMerge ユーティリティなどのツールマージする必要があります。このツールは、共通言語ランタイム SDK には含まれていません。

空の引数文字列は、単一空白として書き込まれます。引数文字列null 文字は、空白に置き換えられます。

情報は、この動的アセンブリ定義するために使用した AssemblyName オブジェクトを基に決定されます。このアセンブリカスタム属性によって、AssemblyName オブジェクト指定した情報オーバーライドされます

使用例使用例

次の例は、DefineVersionInfoResource使用法示してます。

Imports System
Imports System.Reflection
Imports System.Reflection.Emit

Module Example

   Sub Main()

      Dim assemName As New
 AssemblyName()
      assemName.Name = "EmittedAssembly"

      ' Create a dynamic assembly in the current application domain
,
      ' specifying that the assembly is to be saved.
      '
      Dim myAssembly As AssemblyBuilder = _
         AppDomain.CurrentDomain.DefineDynamicAssembly(assemName, _
            AssemblyBuilderAccess.Save)


      ' To apply an attribute to a dynamic assembly, first get the 
      ' attribute type. The AssemblyFileVersionAttribute sets the 
      ' File Version field on the Version tab of the Windows file
      ' properties dialog.
      '
      Dim attributeType As Type = GetType(AssemblyFileVersionAttribute)

      ' To identify the constructor, use an array of types representing
      ' the constructor's parameter types. This ctor takes a string.
      '
      Dim ctorParameters() As Type = { GetType(String)
 }

      ' Get the constructor for the attribute.
      '
      Dim ctor As ConstructorInfo = _
                         attributeType.GetConstructor(ctorParameters)

      ' Pass the constructor and an array of arguments (in this case
,
      ' an array containing a single string) to the 
      ' CustomAttributeBuilder constructor.
      '
      Dim ctorArgs() As Object
 = { "2.0.3033.0" }
      Dim attribute As New
 CustomAttributeBuilder(ctor, ctorArgs)

      ' Finally, apply the attribute to the assembly.
      '
      myAssembly.SetCustomAttribute(attribute)


      ' The pattern described above is used to create and apply
      ' several more attributes. As it happens, all these attributes
      ' have a constructor that takes a string, so the same ctorArgs
      ' variable works for all of them.
      

      ' The AssemblyTitleAttribute sets the Description field on
      ' the General tab and the Version tab of the Windows file 
      ' properties dialog.
      '
      attributeType = GetType(AssemblyTitleAttribute)
      ctor = attributeType.GetConstructor(ctorParameters)
      ctorArgs = New Object() { "The
 Application Title" }
      attribute = New CustomAttributeBuilder(ctor, ctorArgs)
      myAssembly.SetCustomAttribute(attribute)

      ' The AssemblyCopyrightAttribute sets the Copyright field on
      ' the Version tab.
      '
      attributeType = GetType(AssemblyCopyrightAttribute)
      ctor = attributeType.GetConstructor(ctorParameters)
      ctorArgs = New Object() { "
 My Example Company 1991-2005" }
      attribute = New CustomAttributeBuilder(ctor, ctorArgs)
      myAssembly.SetCustomAttribute(attribute)

      ' The AssemblyDescriptionAttribute sets the Comment item.
      '
      attributeType = GetType(AssemblyDescriptionAttribute)
      ctor = attributeType.GetConstructor(ctorParameters)
      attribute = New CustomAttributeBuilder(ctor, _
         New Object() { "This
 is a comment." })
      myAssembly.SetCustomAttribute(attribute)

      ' The AssemblyCompanyAttribute sets the Company item.
      '
      attributeType = GetType(AssemblyCompanyAttribute)
      ctor = attributeType.GetConstructor(ctorParameters)
      attribute = New CustomAttributeBuilder(ctor, _
         New Object() { "My
 Example Company" })
      myAssembly.SetCustomAttribute(attribute)

      ' The AssemblyProductAttribute sets the Product Name item.
      '
      attributeType = GetType(AssemblyProductAttribute)
      ctor = attributeType.GetConstructor(ctorParameters)
      attribute = New CustomAttributeBuilder(ctor, _
         New Object() { "My
 Product Name" })
      myAssembly.SetCustomAttribute(attribute)


      ' Define the assembly's only module. For a single-file assembly
,
      ' the module name is the assembly name.
      '
      Dim myModule As ModuleBuilder = _
         myAssembly.DefineDynamicModule(assemName.Name, _
            assemName.Name & ".exe")

      ' No types or methods are created for this example.


      ' Define the unmanaged version information resource, which
      ' contains the attribute informaion applied earlier, and save
      ' the assembly. Use the Windows Explorer to examine the properties
      ' of the .exe file.
      '
      myAssembly.DefineVersionInfoResource()
      myAssembly.Save(assemName.Name & ".exe")

   End Sub 
End Module
using System;
using System.Reflection;
using System.Reflection.Emit;

class Example
{
   public static void Main()
   {
      AssemblyName assemName = new AssemblyName();
      assemName.Name = "EmittedAssembly";

      // Create a dynamic assembly in the current application domain
,
      // specifying that the assembly is to be saved.
      //
      AssemblyBuilder myAssembly = 
         AppDomain.CurrentDomain.DefineDynamicAssembly(assemName, 
            AssemblyBuilderAccess.Save);


      // To apply an attribute to a dynamic assembly, first get the
 
      // attribute type. The AssemblyFileVersionAttribute sets the 
      // File Version field on the Version tab of the Windows file
      // properties dialog.
      //
      Type attributeType = typeof(AssemblyFileVersionAttribute);

      // To identify the constructor, use an array of types representing
      // the constructor's parameter types. This ctor takes a string.
      //
      Type[] ctorParameters = { typeof(string) };

      // Get the constructor for the attribute.
      //
      ConstructorInfo ctor = attributeType.GetConstructor(ctorParameters);

      // Pass the constructor and an array of arguments (in this case
,
      // an array containing a single string) to the 
      // CustomAttributeBuilder constructor.
      //
      object[] ctorArgs = { "2.0.3033.0" };
      CustomAttributeBuilder attribute = 
         new CustomAttributeBuilder(ctor, ctorArgs);

      // Finally, apply the attribute to the assembly.
      //
      myAssembly.SetCustomAttribute(attribute);


      // The pattern described above is used to create and apply
      // several more attributes. As it happens, all these attributes
      // have a constructor that takes a string, so the same ctorArgs
      // variable works for all of them.
      

      // The AssemblyTitleAttribute sets the Description field on
      // the General tab and the Version tab of the Windows file 
      // properties dialog.
      //
      attributeType = typeof(AssemblyTitleAttribute);
      ctor = attributeType.GetConstructor(ctorParameters);
      ctorArgs = new object[] { "The Application Title"
 };
      attribute = new CustomAttributeBuilder(ctor, ctorArgs);
      myAssembly.SetCustomAttribute(attribute);

      // The AssemblyCopyrightAttribute sets the Copyright field on
      // the Version tab.
      //
      attributeType = typeof(AssemblyCopyrightAttribute);
      ctor = attributeType.GetConstructor(ctorParameters);
      ctorArgs = new object[] { " My Example Company 1991-2005"
 };
      attribute = new CustomAttributeBuilder(ctor, ctorArgs);
      myAssembly.SetCustomAttribute(attribute);

      // The AssemblyDescriptionAttribute sets the Comment item.
      //
      attributeType = typeof(AssemblyDescriptionAttribute);
      ctor = attributeType.GetConstructor(ctorParameters);
      attribute = new CustomAttributeBuilder(ctor, 
         new object[] { "This is a comment." });
      myAssembly.SetCustomAttribute(attribute);

      // The AssemblyCompanyAttribute sets the Company item.
      //
      attributeType = typeof(AssemblyCompanyAttribute);
      ctor = attributeType.GetConstructor(ctorParameters);
      attribute = new CustomAttributeBuilder(ctor, 
         new object[] { "My Example Company" });
      myAssembly.SetCustomAttribute(attribute);

      // The AssemblyProductAttribute sets the Product Name item.
      //
      attributeType = typeof(AssemblyProductAttribute);
      ctor = attributeType.GetConstructor(ctorParameters);
      attribute = new CustomAttributeBuilder(ctor, 
         new object[] { "My Product Name" });
      myAssembly.SetCustomAttribute(attribute);


      // Define the assembly's only module. For a single-file assembly
,
      // the module name is the assembly name.
      //
      ModuleBuilder myModule = 
         myAssembly.DefineDynamicModule(assemName.Name, 
            assemName.Name + ".exe");

      // No types or methods are created for this example.


      // Define the unmanaged version information resource, which
      // contains the attribute informaion applied earlier, and save
      // the assembly. Use the Windows Explorer to examine the properties
      // of the .exe file.
      //
      myAssembly.DefineVersionInfoResource();
      myAssembly.Save(assemName.Name + ".exe");

   }
}
using namespace System;
using namespace System::Reflection;
using namespace System::Reflection::Emit;


/*
// Create the callee transient dynamic assembly.
static Type^ CreateAssembly( AppDomain^ myDomain )
{
   AssemblyName^ myAssemblyName = gcnew AssemblyName;
   myAssemblyName->Name = "MyEmittedAssembly";
   AssemblyBuilder^ myAssembly = myDomain->DefineDynamicAssembly( myAssemblyName,
 AssemblyBuilderAccess::Save );
   
   // Set Company Attribute to the assembly.
   Type^ companyAttribute = AssemblyCompanyAttribute::typeid;
   array<Type^>^types1 = {String::typeid};
   ConstructorInfo^ myConstructorInfo1 = companyAttribute->GetConstructor( types1
 );
   array<Object^>^obj1 = {"Microsoft Corporation"};
   CustomAttributeBuilder^ attributeBuilder1 = gcnew CustomAttributeBuilder( myConstructorInfo1,obj1
 );
   myAssembly->SetCustomAttribute( attributeBuilder1 );
   
   // Set Copyright Attribute to the assembly.
   Type^ copyrightAttribute = AssemblyCopyrightAttribute::typeid;
   array<Type^>^types2 = {String::typeid};
   ConstructorInfo^ myConstructorInfo2 = copyrightAttribute->GetConstructor( types2
 );
   array<Object^>^obj2 = {"@Copyright Microsoft Corp. 1990-2001"};
   CustomAttributeBuilder^ attributeBuilder2 = gcnew CustomAttributeBuilder( myConstructorInfo2,obj2
 );
   myAssembly->SetCustomAttribute( attributeBuilder2 );
   ModuleBuilder^ myModule = myAssembly->DefineDynamicModule( "EmittedModule",
 "EmittedModule.mod" );
   
   // Define a public class named S"HelloWorld" in the assembly.
   TypeBuilder^ helloWorldClass = myModule->DefineType( "HelloWorld",
 TypeAttributes::Public );
   
   // Define the Display method.
   MethodBuilder^ myMethod = helloWorldClass->DefineMethod( "Display",
 MethodAttributes::Public, String::typeid, nullptr );
   
   // Generate IL for GetGreeting.
   ILGenerator^ methodIL = myMethod->GetILGenerator();
   methodIL->Emit( OpCodes::Ldstr, "Display method get
 called." );
   methodIL->Emit( OpCodes::Ret );
   
   // Returns the type HelloWorld.
   return (helloWorldClass->CreateType());
}
*/

int main()
{
   AssemblyName^ assemName = gcnew AssemblyName();
   assemName->Name = "EmittedAssembly";

   // Create a dynamic assembly in the current application domain,
   // specifying that the assembly is to be saved.
   //
   AssemblyBuilder^ myAssembly = 
      AppDomain::CurrentDomain->DefineDynamicAssembly(assemName, 
         AssemblyBuilderAccess::Save);


   // To apply an attribute to a dynamic assembly, first get the 
   // attribute type. The AssemblyFileVersionAttribute sets the 
   // File Version field on the Version tab of the Windows file
   // properties dialog.
   //
   Type^ attributeType = AssemblyFileVersionAttribute::typeid;

   // To identify the constructor, use an array of types representing
   // the constructor's parameter types. This ctor takes a string.
   //
   array<Type^>^ ctorParameters = { String::typeid };

   // Get the constructor for the attribute.
   //
   ConstructorInfo^ ctor = attributeType->GetConstructor(ctorParameters);

   // Pass the constructor and an array of arguments (in this case,
   // an array containing a single string) to the 
   // CustomAttributeBuilder constructor.
   //
   array<Object^>^ ctorArgs = { "2.0.3033.0" };
   CustomAttributeBuilder^ attribute = 
      gcnew CustomAttributeBuilder(ctor, ctorArgs);

   // Finally, apply the attribute to the assembly.
   //
   myAssembly->SetCustomAttribute(attribute);


   // The pattern described above is used to create and apply
   // several more attributes. As it happens, all these attributes
   // have a constructor that takes a string, so the same ctorArgs
   // variable works for all of them.
    

   // The AssemblyTitleAttribute sets the Description field on
   // the General tab and the Version tab of the Windows file 
   // properties dialog.
   //
   attributeType = AssemblyTitleAttribute::typeid;
   ctor = attributeType->GetConstructor(ctorParameters);
   ctorArgs = gcnew array<Object^> { "The Application Title" };
   attribute = gcnew CustomAttributeBuilder(ctor, ctorArgs);
   myAssembly->SetCustomAttribute(attribute);

   // The AssemblyCopyrightAttribute sets the Copyright field on
   // the Version tab.
   //
   attributeType = AssemblyCopyrightAttribute::typeid;
   ctor = attributeType->GetConstructor(ctorParameters);
   ctorArgs = gcnew array<Object^> { " My Example Company 1991-2005"
 };
   attribute = gcnew CustomAttributeBuilder(ctor, ctorArgs);
   myAssembly->SetCustomAttribute(attribute);

   // The AssemblyDescriptionAttribute sets the Comment item.
   //
   attributeType = AssemblyDescriptionAttribute::typeid;
   ctor = attributeType->GetConstructor(ctorParameters);
   attribute = gcnew CustomAttributeBuilder(ctor, 
      gcnew array<Object^> { "This is a comment." });
   myAssembly->SetCustomAttribute(attribute);

   // The AssemblyCompanyAttribute sets the Company item.
   //
   attributeType = AssemblyCompanyAttribute::typeid;
   ctor = attributeType->GetConstructor(ctorParameters);
   attribute = gcnew CustomAttributeBuilder(ctor, 
      gcnew array<Object^> { "My Example Company" });
   myAssembly->SetCustomAttribute(attribute);

   // The AssemblyProductAttribute sets the Product Name item.
   //
   attributeType = AssemblyProductAttribute::typeid;
   ctor = attributeType->GetConstructor(ctorParameters);
   attribute = gcnew CustomAttributeBuilder(ctor, 
      gcnew array<Object^> { "My Product Name" });
   myAssembly->SetCustomAttribute(attribute);


   // Define the assembly's only module. For a single-file assembly
,
   // the module name is the assembly name.
   //
   ModuleBuilder^ myModule = 
      myAssembly->DefineDynamicModule(assemName->Name, 
         assemName->Name + ".exe");

   // No types or methods are created for this example.


   // Define the unmanaged version information resource, which
   // contains the attribute informaion applied earlier, and save
   // the assembly. Use the Windows Explorer to examine the properties
   // of the .exe file.
   //
   myAssembly->DefineVersionInfoResource();
   myAssembly->Save(assemName->Name + ".exe");
}
import System.*;
import System.Threading.*;
import System.Reflection.*;
import System.Reflection.Emit.*;
import System.Resources.*;

public class MyEmitTest
{
    public static void main(String[]
 args)
    {
        AssemblyBuilder myAssembly = (AssemblyBuilder)(CreateAssembly(
            System.Threading.Thread.GetDomain()).get_Assembly());
        IResourceWriter myResourceWriter = 
            myAssembly.DefineResource("myResourceFile", 
            "A sample Resource File", "MyResourceFile.resources");

        myResourceWriter.AddResource("AddResource test", "Test resource
 added");

        // Define unmanaged version information resources.
        myAssembly.DefineVersionInfoResource();
        myAssembly.Save("MyEmittedAssembly.dll");
    } //main

    // Create the callee transient dynamic assembly.
    private static Type CreateAssembly(AppDomain
 myDomain) 
    {
        AssemblyName myAssemblyName =  new AssemblyName();
        myAssemblyName.set_Name("MyEmittedAssembly");
        AssemblyBuilder myAssembly = myDomain.DefineDynamicAssembly(
            myAssemblyName, AssemblyBuilderAccess.Save);

        // Set Company Attribute to the assembly.
        Type companyAttribute = AssemblyCompanyAttribute.class.ToType();
        ConstructorInfo myConstructorInfo1 = companyAttribute.GetConstructor(
            new Type[]{String.class.ToType()});
        CustomAttributeBuilder attributeBuilder1 =  
            new CustomAttributeBuilder(myConstructorInfo1, 
            new Object[]{"Microsoft Corporation"});
        myAssembly.SetCustomAttribute(attributeBuilder1);

        // Set Copyright Attribute to the assembly.
        Type copyrightAttribute = AssemblyCopyrightAttribute.class.ToType();
        ConstructorInfo myConstructorInfo2 = copyrightAttribute.GetConstructor(
            new Type[]{String.class.ToType()});
        CustomAttributeBuilder attributeBuilder2 = 
            new CustomAttributeBuilder(myConstructorInfo2, 
            new Object[]{"@Copyright Microsoft Corp. 1990-2001"});
        myAssembly.SetCustomAttribute(attributeBuilder2);

        ModuleBuilder myModule = myAssembly.DefineDynamicModule("EmittedModule"
,
            "EmittedModule.mod");

        // Define a public class named "HelloWorld" in the
 assembly.
        TypeBuilder helloWorldClass = myModule.DefineType("HelloWorld",
 
            TypeAttributes.Public);

        // Define the Display method.
        MethodBuilder myMethod = helloWorldClass.DefineMethod("Display",
 
            MethodAttributes.Public, String.class.ToType(), null);

        // Generate IL for GetGreeting.
        ILGenerator methodIL = myMethod.GetILGenerator();
        methodIL.Emit(OpCodes.Ldstr, "Display method get
 called.");
        methodIL.Emit(OpCodes.Ret);

        // Returns the type HelloWorld.
        return helloWorldClass.CreateType();
    } //CreateAssembly
} //MyEmitTest
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
AssemblyBuilder クラス
AssemblyBuilder メンバ
System.Reflection.Emit 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

AssemblyBuilder.DefineVersionInfoResource メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



AssemblyBuilder.DefineVersionInfoResource メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS