Setting assembly attributes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Madhav Desetty

    #1

    Setting assembly attributes

    I have a legacy C/C++ header file which I use to set the version for
    DLLs thru' the .rc files while compiling legacy DLLs every day. I
    update this header file for every build and would like to use the
    constants I defined in this header file for the .NET projects
    AssemblyInfo.cs file instead of updating the AssemblyInfo.cs for every
    build. Below I came up with a strategy to use the legacy header file
    but it is not working.

    Contents of VersionConstant s.h C/C++ Header legacy file
    ------------------------------------------
    #ifndef _VERSIONCONSTAN TS_H
    #define _VERSIONCONSTAN TS_H
    #endif

    #define VERSIONNUM "6.3.4.123"
    #define COPYRIGHT "Copyright 2003"
    #define COMPANYNAME "My Company Inc."

    #endif // _VERSIONCONSTAN TS_H

    -------------------------------------------

    I created a small managed C++ class something like this:

    #using <mscorlib.dll >
    #include "VersionConstan ts.h"

    namespace MyCompany
    {
    public __gc class VersionInfo
    {
    public static string Copyright = COPYRIGHT;
    public static string VersionNumber = VERSIONNUM;
    public static string CompanyName = COMPANYNAME;
    ...
    }
    }

    In the C# projects, I added a reference to this new assembly and add
    code like this in AssemblyInfo.cs

    C# code (AssemblyInfo.c s):
    ....
    using MyNamespace;
    ....
    [assembly: AssemblyCopyrig ht(MyCompany.Ve rsionInfo.Copyr ight)]
    [assembly: AssemblyVersion (MyCompany.Vers ionInfo.Version Number)];
    ....

    The managed C++ layer is there strictly as the portal from the
    unmanaged world to the managed world so that (managed) C# code can
    access the stuff defined in the (unmanaged code) C/C++ header files.

    When I do that I get compile error at AssemblyCopyrig ht and
    AssmblyVersion attributes in AssemblyInfo.cs file.
    CS0182: An attribute argument must be a constant expression, typeof
    expression or array creation expression.

    I understand why this error is coming because I guess you must have a
    constant expression such as string literal and cannot be a variable.
    Am I at dead end and the only way to do it is updating AssemblyInfo.cs
    everyday.
  • Grant Richins [MS]

    #2
    Re: Setting assembly attributes

    2 suggestions:
    #1 - try making the C++ field 'const'
    #2 - try just using the C++ preprocessor to generate some C# code.
    Something like this

    // AssemblyInfoCon stants.cspp (pre-processed C# code)
    #include "VersionConstan ts.h"

    [assembly: AssemblyCopyrig ht(COPYRIGHT)]
    [assembly: AssemblyVersion (VERSIONNUM)];

    Then preprocess it as a pre-build event (if you're using 2003), or as a
    custom build event of the C++ projects (for 2002).

    --
    --Grant
    This posting is provided "AS IS" with no warranties, and confers no rights.


    "Madhav Desetty" <m_desetty@hotm ail.com> wrote in message
    news:c07e5e8b.0 311180852.76517 139@posting.goo gle.com...[color=blue]
    > I have a legacy C/C++ header file which I use to set the version for
    > DLLs thru' the .rc files while compiling legacy DLLs every day. I
    > update this header file for every build and would like to use the
    > constants I defined in this header file for the .NET projects
    > AssemblyInfo.cs file instead of updating the AssemblyInfo.cs for every
    > build. Below I came up with a strategy to use the legacy header file
    > but it is not working.
    >
    > Contents of VersionConstant s.h C/C++ Header legacy file
    > ------------------------------------------
    > #ifndef _VERSIONCONSTAN TS_H
    > #define _VERSIONCONSTAN TS_H
    > #endif
    >
    > #define VERSIONNUM "6.3.4.123"
    > #define COPYRIGHT "Copyright 2003"
    > #define COMPANYNAME "My Company Inc."
    >
    > #endif // _VERSIONCONSTAN TS_H
    >
    > -------------------------------------------
    >
    > I created a small managed C++ class something like this:
    >
    > #using <mscorlib.dll >
    > #include "VersionConstan ts.h"
    >
    > namespace MyCompany
    > {
    > public __gc class VersionInfo
    > {
    > public static string Copyright = COPYRIGHT;
    > public static string VersionNumber = VERSIONNUM;
    > public static string CompanyName = COMPANYNAME;
    > ...
    > }
    > }
    >
    > In the C# projects, I added a reference to this new assembly and add
    > code like this in AssemblyInfo.cs
    >
    > C# code (AssemblyInfo.c s):
    > ...
    > using MyNamespace;
    > ...
    > [assembly: AssemblyCopyrig ht(MyCompany.Ve rsionInfo.Copyr ight)]
    > [assembly: AssemblyVersion (MyCompany.Vers ionInfo.Version Number)];
    > ...
    >
    > The managed C++ layer is there strictly as the portal from the
    > unmanaged world to the managed world so that (managed) C# code can
    > access the stuff defined in the (unmanaged code) C/C++ header files.
    >
    > When I do that I get compile error at AssemblyCopyrig ht and
    > AssmblyVersion attributes in AssemblyInfo.cs file.
    > CS0182: An attribute argument must be a constant expression, typeof
    > expression or array creation expression.
    >
    > I understand why this error is coming because I guess you must have a
    > constant expression such as string literal and cannot be a variable.
    > Am I at dead end and the only way to do it is updating AssemblyInfo.cs
    > everyday.[/color]


    Comment

    • Madhav Desetty

      #3
      Re: Setting assembly attributes

      Grant, Thanks for you suggestions.

      #1) First suggestion of making C++ field 'const' did not work. This is
      what I did. Did I do it right? Still I got the CS0182 compile error.

      #include "VersionConstan ts.h"

      namespace MyCompany
      {
      public __gc class VersionInfo
      {
      public static const String *Copyright = COPYRIGHT;
      public static const String *VersionNumber = VERSIONNUM;
      public static const String *CompanyName = COMPANYNAME;
      ...
      }
      }

      #2) I am using VS.NET 2002. what do I add to the C++ custom build
      event to generate C# code. i never did anything like that before so I
      am not sure what you are asking me to do.

      I really appreciate your help on this.

      Thanks

      -madhav desetty




      "Grant Richins [MS]" <grantri@online .microsoft.com> wrote in message news:<e#R29ihrD HA.2064@TK2MSFT NGP11.phx.gbl>. ..[color=blue]
      > 2 suggestions:
      > #1 - try making the C++ field 'const'
      > #2 - try just using the C++ preprocessor to generate some C# code.
      > Something like this
      >
      > // AssemblyInfoCon stants.cspp (pre-processed C# code)
      > #include "VersionConstan ts.h"
      >
      > [assembly: AssemblyCopyrig ht(COPYRIGHT)]
      > [assembly: AssemblyVersion (VERSIONNUM)];
      >
      > Then preprocess it as a pre-build event (if you're using 2003), or as a
      > custom build event of the C++ projects (for 2002).
      >
      > --
      > --Grant
      > This posting is provided "AS IS" with no warranties, and confers no rights.
      >
      >
      > "Madhav Desetty" <m_desetty@hotm ail.com> wrote in message
      > news:c07e5e8b.0 311180852.76517 139@posting.goo gle.com...[color=green]
      > > I have a legacy C/C++ header file which I use to set the version for
      > > DLLs thru' the .rc files while compiling legacy DLLs every day. I
      > > update this header file for every build and would like to use the
      > > constants I defined in this header file for the .NET projects
      > > AssemblyInfo.cs file instead of updating the AssemblyInfo.cs for every
      > > build. Below I came up with a strategy to use the legacy header file
      > > but it is not working.
      > >
      > > Contents of VersionConstant s.h C/C++ Header legacy file
      > > ------------------------------------------
      > > #ifndef _VERSIONCONSTAN TS_H
      > > #define _VERSIONCONSTAN TS_H
      > > #endif
      > >
      > > #define VERSIONNUM "6.3.4.123"
      > > #define COPYRIGHT "Copyright 2003"
      > > #define COMPANYNAME "My Company Inc."
      > >
      > > #endif // _VERSIONCONSTAN TS_H
      > >
      > > -------------------------------------------
      > >
      > > I created a small managed C++ class something like this:
      > >
      > > #using <mscorlib.dll >
      > > #include "VersionConstan ts.h"
      > >
      > > namespace MyCompany
      > > {
      > > public __gc class VersionInfo
      > > {
      > > public static string Copyright = COPYRIGHT;
      > > public static string VersionNumber = VERSIONNUM;
      > > public static string CompanyName = COMPANYNAME;
      > > ...
      > > }
      > > }
      > >
      > > In the C# projects, I added a reference to this new assembly and add
      > > code like this in AssemblyInfo.cs
      > >
      > > C# code (AssemblyInfo.c s):
      > > ...
      > > using MyNamespace;
      > > ...
      > > [assembly: AssemblyCopyrig ht(MyCompany.Ve rsionInfo.Copyr ight)]
      > > [assembly: AssemblyVersion (MyCompany.Vers ionInfo.Version Number)];
      > > ...
      > >
      > > The managed C++ layer is there strictly as the portal from the
      > > unmanaged world to the managed world so that (managed) C# code can
      > > access the stuff defined in the (unmanaged code) C/C++ header files.
      > >
      > > When I do that I get compile error at AssemblyCopyrig ht and
      > > AssmblyVersion attributes in AssemblyInfo.cs file.
      > > CS0182: An attribute argument must be a constant expression, typeof
      > > expression or array creation expression.
      > >
      > > I understand why this error is coming because I guess you must have a
      > > constant expression such as string literal and cannot be a variable.
      > > Am I at dead end and the only way to do it is updating AssemblyInfo.cs
      > > everyday.[/color][/color]

      Comment

      • Grant Richins [MS]

        #4
        Re: Setting assembly attributes

        Well I'm no C++ expert, but the more I try it seems like C++ can't create
        managed constants...

        So for #2
        // AssemblyVersion .cspp
        #include "versionconstan ts.h"
        using System.Reflecti on;

        [assembly: AssemblyCopyrig ht( COPYRIGHT )]
        [assembly: AssemblyVersion ( VERSIONNUM )];

        // run it through the C++ preprocessor to get a normal C# file
        cl.exe /E AssemblyVersion .cspp > AssemblyVersion .cs


        --
        --Grant
        This posting is provided "AS IS" with no warranties, and confers no rights.


        "Madhav Desetty" <m_desetty@hotm ail.com> wrote in message
        news:c07e5e8b.0 311192213.60f13 794@posting.goo gle.com...[color=blue]
        > Grant, Thanks for you suggestions.
        >
        > #1) First suggestion of making C++ field 'const' did not work. This is
        > what I did. Did I do it right? Still I got the CS0182 compile error.
        >
        > #include "VersionConstan ts.h"
        >
        > namespace MyCompany
        > {
        > public __gc class VersionInfo
        > {
        > public static const String *Copyright = COPYRIGHT;
        > public static const String *VersionNumber = VERSIONNUM;
        > public static const String *CompanyName = COMPANYNAME;
        > ...
        > }
        > }
        >
        > #2) I am using VS.NET 2002. what do I add to the C++ custom build
        > event to generate C# code. i never did anything like that before so I
        > am not sure what you are asking me to do.
        >
        > I really appreciate your help on this.
        >
        > Thanks
        >
        > -madhav desetty
        >
        >
        >
        >
        > "Grant Richins [MS]" <grantri@online .microsoft.com> wrote in message[/color]
        news:<e#R29ihrD HA.2064@TK2MSFT NGP11.phx.gbl>. ..[color=blue][color=green]
        > > 2 suggestions:
        > > #1 - try making the C++ field 'const'
        > > #2 - try just using the C++ preprocessor to generate some C# code.
        > > Something like this
        > >
        > > // AssemblyInfoCon stants.cspp (pre-processed C# code)
        > > #include "VersionConstan ts.h"
        > >
        > > [assembly: AssemblyCopyrig ht(COPYRIGHT)]
        > > [assembly: AssemblyVersion (VERSIONNUM)];
        > >
        > > Then preprocess it as a pre-build event (if you're using 2003), or as a
        > > custom build event of the C++ projects (for 2002).
        > >
        > > --
        > > --Grant
        > > This posting is provided "AS IS" with no warranties, and confers no[/color][/color]
        rights.[color=blue][color=green]
        > >
        > >
        > > "Madhav Desetty" <m_desetty@hotm ail.com> wrote in message
        > > news:c07e5e8b.0 311180852.76517 139@posting.goo gle.com...[color=darkred]
        > > > I have a legacy C/C++ header file which I use to set the version for
        > > > DLLs thru' the .rc files while compiling legacy DLLs every day. I
        > > > update this header file for every build and would like to use the
        > > > constants I defined in this header file for the .NET projects
        > > > AssemblyInfo.cs file instead of updating the AssemblyInfo.cs for every
        > > > build. Below I came up with a strategy to use the legacy header file
        > > > but it is not working.
        > > >
        > > > Contents of VersionConstant s.h C/C++ Header legacy file
        > > > ------------------------------------------
        > > > #ifndef _VERSIONCONSTAN TS_H
        > > > #define _VERSIONCONSTAN TS_H
        > > > #endif
        > > >
        > > > #define VERSIONNUM "6.3.4.123"
        > > > #define COPYRIGHT "Copyright 2003"
        > > > #define COMPANYNAME "My Company Inc."
        > > >
        > > > #endif // _VERSIONCONSTAN TS_H
        > > >
        > > > -------------------------------------------
        > > >
        > > > I created a small managed C++ class something like this:
        > > >
        > > > #using <mscorlib.dll >
        > > > #include "VersionConstan ts.h"
        > > >
        > > > namespace MyCompany
        > > > {
        > > > public __gc class VersionInfo
        > > > {
        > > > public static string Copyright = COPYRIGHT;
        > > > public static string VersionNumber = VERSIONNUM;
        > > > public static string CompanyName = COMPANYNAME;
        > > > ...
        > > > }
        > > > }
        > > >
        > > > In the C# projects, I added a reference to this new assembly and add
        > > > code like this in AssemblyInfo.cs
        > > >
        > > > C# code (AssemblyInfo.c s):
        > > > ...
        > > > using MyNamespace;
        > > > ...
        > > > [assembly: AssemblyCopyrig ht(MyCompany.Ve rsionInfo.Copyr ight)]
        > > > [assembly: AssemblyVersion (MyCompany.Vers ionInfo.Version Number)];
        > > > ...
        > > >
        > > > The managed C++ layer is there strictly as the portal from the
        > > > unmanaged world to the managed world so that (managed) C# code can
        > > > access the stuff defined in the (unmanaged code) C/C++ header files.
        > > >
        > > > When I do that I get compile error at AssemblyCopyrig ht and
        > > > AssmblyVersion attributes in AssemblyInfo.cs file.
        > > > CS0182: An attribute argument must be a constant expression, typeof
        > > > expression or array creation expression.
        > > >
        > > > I understand why this error is coming because I guess you must have a
        > > > constant expression such as string literal and cannot be a variable.
        > > > Am I at dead end and the only way to do it is updating AssemblyInfo.cs
        > > > everyday.[/color][/color][/color]


        Comment

        Working...