473,509 Members | 2,951 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Assembly ?

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
Nov 15 '05 #1
5 4982
John <jo***********@hotmail.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
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" <jo***********@hotmail.com> wrote in message
news:uX**************@TK2MSFTNGP10.phx.gbl...
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

Nov 15 '05 #3

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
John <jo***********@hotmail.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


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
Nov 15 '05 #4
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" <st***@mckraken.com> wrote in message
news:Ok**************@TK2MSFTNGP12.phx.gbl...
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" <jo***********@hotmail.com> wrote in message
news:uX**************@TK2MSFTNGP10.phx.gbl...
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


Nov 15 '05 #5
John <jo***********@hotmail.com> wrote:
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.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
8760
by: Terence Shek | last post by:
Is there a way to set the application binding policy so that it always binds to the latest version of an assembly? I'm hoping there is a way to avoid updating the application's binding...
26
10508
by: nospam | last post by:
Just wondering, What do you think the difference in performance would be between (1.) Compiled C# (2.) Compiled C++ (3.) and Assembly Language And how would the mix be if some if any of...
2
6385
by: Carlos G Benevides | last post by:
I have a ASP.Net web application that has two assemblies that run under com+. Under Windows 2000 the two assemblies are added to com+ automatically when instantiated from the web site. For this...
10
3416
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
7
10936
by: R Reyes | last post by:
Can someone please explain to me why I can't get the MS Word Interop assembly to work in my VS2005 project? I'm trying to manipulate MS Word from my Web Form application and I can't get passed...
3
4384
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here...
1
2349
by: Tim F | last post by:
Problem: I'm receiving the error "File or assembly name XXXXX or one of its dependencies, was not found." when trying to execute code in an assmebly that has both a strong-name and has been...
2
11758
by: Paul | last post by:
Hi, I have experience in Java and C++ but I am rather new to C# and just started learning it. I am using Visual C# 2005 Express Edition and I found that there is a file called "AssemblyInfo.cs",...
1
2238
by: Coaster | last post by:
orig ref here http://groups.google.com/group/microsoft.public.dotnet.framework.aspnet/browse_thread/thread/ff29cc370678911d/c0db5b7e3da283b9?lnk=st&q=gac+assembly+new+version&rnum=7#c0db5b7e3da283b9...
14
2642
by: Monty | last post by:
Hello, I have created a solution which has both a web UI and a winform UI, the latter is just for administrators. The Web UI (a Web Application Project) and the winform project both...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7347
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7416
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7073
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
779
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
443
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.