473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

.Net 2.0 Framework Strong Name Error


Hi

I am in the Process of conversion of my existing 1.1 Dotnet Code to 2.0
framework.

for each project when i compile in VS2005 , i get this error\warning:

Use command line option '/keyfile' or appropriate project settings instead
of 'AssemblyKeyFile'

The conversion for this is to edit the location of the assemblyinfo.cs file.

I have around 200 Solution files in my project.

Any one know any Utility for this change process??
Any projects available in Source Forge.Net ?

Or does Microsoft itself gets any utility for this ?

Thanks
Senthil
Jun 16 '06 #1
1 1322
Long code warning...

The following console app seems to work for key-containers (I try to avoid
working with key-files); using this and the information in my reply
yesterday, plus "before vs after" (windiff) at what exactly the UI does to
the project file when setting the key-file in the IDE, you should be able to
get it to work with key-files in about half-an-hour. I haven't tested it
much... you may need to fix bits of it... but it worked for my test cases.

Good luck.

Marc
===
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Xml;
using System.Text.RegularExpressions;

namespace AssemblyKey {
class Program {
static bool _verbose = false;
static int Main(string[] args) {
List<string> projects = new List<string>();
bool recurse = false, valid = true, showHelp = false;
foreach (string arg in args) {
if (arg.StartsWith("-")) {
switch(arg) {
case "-h":
case "-?":
showHelp = true; break;
case "-r":
recurse = true; break;
case "-v":
_verbose = true; break;
default:
Console.WriteLine("Invalid option \"{0}\"",
arg);
valid = false; break;
}
} else {
string path = arg;
if (PreCheckProject(ref path)) {
projects.Add(path);
} else {
valid = false;
}
}
if(recurse) {
try { // following can fail for various recursive
reasons
foreach (string pathItem in
Directory.GetFiles(Environment.CurrentDirectory, "*.csproj",
SearchOption.AllDirectories)) {
string path = pathItem; // ref/foreach
if (PreCheckProject(ref path)) {
projects.Add(path);
} else {
valid = false;
}
}
} catch (Exception ex) {
Console.WriteLine(ex.GetType().Name + ": " +
ex.Message);
valid = false; // but keep going anyway
}
}
}

if (projects.Count == 0)
showHelp = true;
if (valid) {
if (showHelp) {
Console.WriteLine("\t{0} -? | -h | -r | {{project path
[project path...]} [-v]}", Process.GetCurrentProcess().ProcessName);
Console.WriteLine("\t\t-r\t\tRecurse from current
directory");
Console.WriteLine("\t\t-v\t\tVerbose");
Console.WriteLine("\t\t-?, -h\t\tHelp");
} else {
foreach (string path in projects) {
try {
ProcessProject(path);
} catch (Exception ex) {
Console.WriteLine(ex.GetType().Name + ": " +
ex.Message);
valid = false; // but keep going anyway
}
}
}
}

return valid ? 0 : -1;

}
static bool IsFileReadOnly(string path) {
return (File.GetAttributes(path) & FileAttributes.ReadOnly) ==
FileAttributes.ReadOnly;
}
static bool PreCheckProject(ref string path) {
path = Path.GetFullPath(path);
if (!File.Exists(path)) {
Console.WriteLine("File not found: {0}", path);
return false;
}
if (IsFileReadOnly(path)) {
Console.WriteLine("File is read only: {0}", path);
return false;
}
return true;
}
static void ProcessProject(string path) {
Verbose("Processing {0}", path);
bool update = false;
string projectRoot = new FileInfo(path).Directory.FullName;
XmlDocument project = new XmlDocument();
project.Load(path);
XmlNamespaceManager nm = new
XmlNamespaceManager(project.NameTable);
nm.AddNamespace("x", project.DocumentElement.NamespaceURI);
XmlElement group =
(XmlElement)project.SelectSingleNode("/x:Project/x:PropertyGroup[not(@Condition)][1]",
nm);
foreach(XmlElement el in
project.SelectNodes("/x:Project/x:ItemGroup/x:Compile[@Include]", nm)) {
string classFile = el.SelectSingleNode("@Include").Value;
if (classFile.EndsWith("AssemblyInfo.cs")) {
string keyName;
ProcessAssemblyInfo(Path.Combine(projectRoot,
classFile), out keyName);
if (!string.IsNullOrEmpty(keyName)) {
update |= SetChildElement(group, "KeyContainerName",
keyName);
}
}
}
if (update) {
project.Save(path);
}
}

private static bool SetChildElement(XmlElement parent, string
elementName, string value) {
bool updated = false;
XmlDocument doc = parent.OwnerDocument;
XmlNamespaceManager nm = new XmlNamespaceManager(doc.NameTable);
nm.AddNamespace("x", parent.NamespaceURI);
XmlElement child = (XmlElement)parent.SelectSingleNode("x:" +
elementName, nm);
if (child == null) {
child =
(XmlElement)parent.AppendChild(doc.CreateElement(e lementName,parent.NamespaceURI));
child.InnerText = value;
Verbose("Added element {0} = {1}", elementName, value);
updated = true;
} else if(child.InnerText != value) {
child.InnerText = value;
Verbose("Updated element {0} = {1}", elementName, value);
updated = true;
}
return updated;
}
private static void Verbose(string format, params object[] args) {
if (_verbose) {
Console.WriteLine(format, args);
}
}
static Regex _keyFileRegex = new
Regex(@"(\[\s*assembly:\s*AssemblyKeyName\(\s*"")([^""]*)(""\s*\)\s*\])",
RegexOptions.Compiled);

static void ProcessAssemblyInfo(string path, out string keyName) {
Verbose("Processing {0}", path);
keyName = null;
bool update = false;
string allText = File.ReadAllText(path);
Match match = _keyFileRegex.Match(allText);
if (match.Success) {
keyName = match.Groups[2].Value;
Verbose("Found key-name {0}", keyName);
allText = _keyFileRegex.Replace(allText, "");
update = true;
}
if (update) {
File.WriteAllText(path, allText);
}
}
}
}
Jun 16 '06 #2

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

Similar topics

0
by: Mário Sobral | last post by:
Hi, I created an assembly (let's call it assembly (B)) that returns a localized resource for a given key (similar to System.Globalization.ResourceManager). I checks if the caller assembly (let's...
1
by: Namratha Shah \(Nasha\) | last post by:
Hey Guys, Before we start with our sample app we need to view the security configuration files on the machine. You will find them under <drive>\WInNT\Microsoft.NET\FrameWork\<version>\Config ...
0
by: Namratha Shah \(Nasha\) | last post by:
Type Library Importer : tlbImp This tool is used to convert the type library definitons found in COM components to .NET assembly. This tool works on the entire type library at the same time...
6
by: Manuel Lopez | last post by:
Hello, I have a Web Project (UserControls.dll) with some user controls that is shared by many asp.net web applicattions. What we do is copy UserControls.dll to all the applications bin...
9
by: Derek Martin | last post by:
<Sigh> - okay, I have given up on the hashing idea, I guess I am going to have to break down and figure the sn gooo out. I keep getting this message when strong naming my assembly (an exe): ...
0
by: Shannon Broskie | last post by:
I'm posting this here as I first found the issue trying to run a 2.0 Framework app on a 2003 server. Background -------------- We utilize a strong name policy sent to all XP machines using...
10
by: Chubbly Geezer | last post by:
I have been working on a VB 2005 DLL which has previously been working. I would create the DLL (reporting.dll), install it, run 'gacutil' and 'regasm' and my Access 2000 DB could see it and use...
7
by: therod | last post by:
I am running Windows Server 2003 SP1 and .Net Framework 1.1 I want to upgrade to .Net 2.0 and I'm pretty sure I should uninstall 1.1 first. Problem is that .NET 1.1 doesn't show up in Control...
25
by: Blasting Cap | last post by:
I keep getting errors that pop up when I am trying to convert an application from dotnet framework 1.1 to framework 2.0. The old project was saved in sourcesafe from Visual Studio 2003, and I have...
2
by: Manikandan | last post by:
Hi, I have a program written in .Net Framework 1.1 using Visual studio enterprise edition 2003. I tried compiling the same program in visual c# express edition 2005. I'm getting following...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.