M
Madhav Desetty
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 VersionConstants.h C/C++ Header legacy file
------------------------------------------
#ifndef _VERSIONCONSTANTS_H
#define _VERSIONCONSTANTS_H
#endif
#define VERSIONNUM "6.3.4.123"
#define COPYRIGHT "Copyright 2003"
#define COMPANYNAME "My Company Inc."
#endif // _VERSIONCONSTANTS_H
-------------------------------------------
I created a small managed C++ class something like this:
#using <mscorlib.dll>
#include "VersionConstants.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.cs):
....
using MyNamespace;
....
[assembly: AssemblyCopyright(MyCompany.VersionInfo.Copyright)]
[assembly: AssemblyVersion(MyCompany.VersionInfo.VersionNumber)];
....
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 AssemblyCopyright 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.
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 VersionConstants.h C/C++ Header legacy file
------------------------------------------
#ifndef _VERSIONCONSTANTS_H
#define _VERSIONCONSTANTS_H
#endif
#define VERSIONNUM "6.3.4.123"
#define COPYRIGHT "Copyright 2003"
#define COMPANYNAME "My Company Inc."
#endif // _VERSIONCONSTANTS_H
-------------------------------------------
I created a small managed C++ class something like this:
#using <mscorlib.dll>
#include "VersionConstants.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.cs):
....
using MyNamespace;
....
[assembly: AssemblyCopyright(MyCompany.VersionInfo.Copyright)]
[assembly: AssemblyVersion(MyCompany.VersionInfo.VersionNumber)];
....
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 AssemblyCopyright 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.