Assembly ?

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hello,

I would like to create a global string variable in my assemblyinfo.cs file.
This string will contain the value of my version info. Can anybody tell me
how to create a global string value in assemblyinfo.cs?

I have the following code after using System.Runtime.CompilerServices;:
string s;

I keep getting the following error:
A namespace does not directly contain members such as fields or methods.
Expected class, delegate, enum, interface, or struct.

I tried to create a class but was unsuccessful. Any ideas?

Thanks,
-- John
 
John said:
I would like to create a global string variable in my assemblyinfo.cs file.
This string will contain the value of my version info. Can anybody tell me
how to create a global string value in assemblyinfo.cs?

I have the following code after using System.Runtime.CompilerServices;:
string s;

I keep getting the following error:
A namespace does not directly contain members such as fields or methods.
Expected class, delegate, enum, interface, or struct.

I tried to create a class but was unsuccessful. Any ideas?

The file you have it in is irrelevant, but all fields *must* be part of
a class.
 
John,

You have to do to things to accomplish this:
1) The field ("global string variable") you create must be in a class or
struct definition

2) The field must be constant - so you'll have to create a string declared
public const string versionInfoString = "1.1.1.1";
in some class or struct.

Not to say you shouldn't do this, but is there a reason you want to do it
this way? the version can't be changed at runtime and you can get the
current version number of the assembly as a string fairly simply:

System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString
();

If you really, really want to, you can do it like this:
in the assemblyinfo.cs, change the [assembly: AssemblyVersion(... line to:
[assembly: AssemblyVersion(MyApp.Constants.VersionInfoString)]

Put this at the END of your assembly info
namespace MyApp
{
public struct Constants
{
public const string VersionInfoString = "1.1.1.1";
}
}


But as stated above, this really doesn't get you much. The one use I can
see for it would be to include the same
file with that struct in many different assemblies that you wanted the
version number synched on.
 
Jon Skeet said:
The file you have it in is irrelevant, but all fields *must* be part of
a class.

Thanks Jon. I've tried to create a class in the assemblyinfo.cs file, but
how do I create an instance of that class once it is create in the
assemblyinfo.cs file? I just want to put the string variable on the
[assembly: AssemblyVersion(stringvariable)] line.

I tried to create a class:

class myString
{
string s;
}

However, I still can't access the s member of myString class because I can't
create an instance of it in the assemblyinfo.cs.

Any other ideas?

Thanks again,
John
 
John said:
Thanks Jon. I've tried to create a class in the assemblyinfo.cs file, but
how do I create an instance of that class once it is create in the
assemblyinfo.cs file?

Why do you particularly want to create an instance of it? You can make
it a static variable. It's just a class, the same as any other class.

Why do you want to put the class definition in the AssemblyInfo.cs file
in the first place? There's nothing special about that file - it just
happens to be a conventional place to put assembly-level attributes.
 
Thanks Philip. That's exactly what I wanted. I believe that the reason why
I need this is so that I can read the version info out of a header file from
another project. One of the other developers here wants a way to
automatically set the version by just changing his value in his header file.

Thanks again,
-- John

Philip Rieck said:
John,

You have to do to things to accomplish this:
1) The field ("global string variable") you create must be in a class or
struct definition

2) The field must be constant - so you'll have to create a string declared
public const string versionInfoString = "1.1.1.1";
in some class or struct.

Not to say you shouldn't do this, but is there a reason you want to do it
this way? the version can't be changed at runtime and you can get the
current version number of the assembly as a string fairly simply:

System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString
();

If you really, really want to, you can do it like this:
in the assemblyinfo.cs, change the [assembly: AssemblyVersion(... line to:
[assembly: AssemblyVersion(MyApp.Constants.VersionInfoString)]

Put this at the END of your assembly info
namespace MyApp
{
public struct Constants
{
public const string VersionInfoString = "1.1.1.1";
}
}


But as stated above, this really doesn't get you much. The one use I can
see for it would be to include the same
file with that struct in many different assemblies that you wanted the
version number synched on.


John said:
Hello,

I would like to create a global string variable in my assemblyinfo.cs file.
This string will contain the value of my version info. Can anybody tell me
how to create a global string value in assemblyinfo.cs?

I have the following code after using System.Runtime.CompilerServices;:
string s;

I keep getting the following error:
A namespace does not directly contain members such as fields or methods.
Expected class, delegate, enum, interface, or struct.

I tried to create a class but was unsuccessful. Any ideas?

Thanks,
-- John
 
Back
Top