Get assembly name at compile time in Visual Studio
Is there a way to find out the assembly name at design time (i.e. not use in Visual Studio?
The script requires a tool to get the assembly name, which will eventually be compiled by the Visual Studio project.
This is similar to parsing the AssemblyName.csproj property. I am wondering if there are any APIs that can reliably convey this information.
Please do not respond to runtime APIs that use reflection - there is no assembly file present at the time I need the assembly name - only assembly metadata in the csproj file.
source to share
if you call the tool through the post / pre-build event, this data is very readily available.
Simply go to the Project Properties → Build Events tab, then select either edit pre-build or edit post-build, whichever you want the tool to run. This should bring up an edit window with a useful "Macros →" button. Click that button and you will be presented with a bunch of macros to use and should be pretty much everything you need.
source to share
After a quick start on MSDN, I found this article that might be a good start for further research:
Access to specific project, project type and project properties
source to share
I think you will need to write a regex that will give you the value of the AssemblyTitle attribute in the AssemblyInfo.cs file.
Something like that:
public class Assembly
{
public static string GetTitle (string fileFullName) {
var contents = File.ReadAllText (fileFullName); //may raise exception if file doesn't exist
//regex string is: AssemblyTitle\x20*\(\x20*"(?<Title>.*)"\x20*\)
//loading from settings because it is annoying to type it in editor
var reg = new Regex (Settings.Default.Expression);
var match = reg.Match (contents);
var titleGroup = match.Groups["Title"];
return (match.Success && titleGroup.Success) ? titleGroup.Value : String.Empty;
}
}
source to share