Introduction
This article describes a simple macro that creates a template manifest file for your application.
The manifest file is created once, the first time you run this macro into an active project. The file is then placed in your resource folder and added to your project as "YourApplication.exe.Manifest". Then, for each configuration (debug, release...) that you have in your project, this macro will add a custom build operation to be able to copy the manifest resource file beside your executable when you build the application.
When the macro has been run, you can modify the manifest template file directly in your project to suit your needs and then save it. Each time you build your application, the manifest file in the output directory will be updated.
This is my first attempt in writing macros, so kindly apologize for mistakes if any, since the language isn't so powerful. I wasn't able to do it the way I wanted to. If I have the time, I will probably do an add-in instead.
private const FileString1 = "<?xml version=""1.0""
encoding=""UTF-8""
standalone=""yes""?>"
private const FileString2 = "<assembly
xmlns=""urn:schemas-microsoft-com:asm.v1""
manifestVersion=""1.0"">"
private const FileString3 = "<assemblyIdentity"
private const FileString4 = " version=""1.0.0.1"""
private const FileString5 = " processorArchitecture=""x86"""
private const FileString6a = " name=""Microsoft.Windows."
private const FileString6b = """"
private const FileString7 = " type=""win32"""
private const FileString8 = "/>"
private const FileString9a = "<description>"
private const FileString9b = "</description>"
private const FileString10 = "<dependency>"
private const FileString11 = " <dependentAssembly>"
private const FileString12 = " <assemblyIdentity"
private const FileString13 = " type=""win32"""
private const FileString14 = " name=""Microsoft.Windows.Common-Controls"""
private const FileString15 = " version=""6.0.0.0"""
private const FileString16 = " processorArchitecture=""X86"""
private const FileString17 = " publicKeyToken=""6595b64144ccf1df"""
private const FileString18 = " language=""*"""
private const FileString19 = " />"
private const FileString20 = " </dependentAssembly>"
private const FileString21 = "</dependency>"
private const FileString22 = "</assembly>"
Sub MakeManifest()
ExecuteCommand "WorkspaceSave"
dim OutString
OutString = FileString1 + vbCrLf
OutString = OutString + FileString2 + vbCrLf
OutString = OutString + FileString3 + vbCrLf
OutString = OutString + FileString4 + vbCrLf
OutString = OutString + FileString5 + vbCrLf
OutString = OutString + FileString6a
OutString = OutString + Application.ActiveProject.Name
OutString = OutString + FileString6b + vbCrLf
OutString = OutString + FileString7 + vbCrLf
OutString = OutString + FileString8 + vbCrLf
OutString = OutString + FileString9a
OutString = OutString + Application.ActiveProject.Name
OutString = OutString + FileString9b + vbCrLf
OutString = OutString + FileString10 + vbCrLf
OutString = OutString + FileString11 + vbCrLf
OutString = OutString + FileString12 + vbCrLf
OutString = OutString + FileString13 + vbCrLf
OutString = OutString + FileString14 + vbCrLf
OutString = OutString + FileString15 + vbCrLf
OutString = OutString + FileString16 + vbCrLf
OutString = OutString + FileString17 + vbCrLf
OutString = OutString + FileString18 + vbCrLf
OutString = OutString + FileString19 + vbCrLf
OutString = OutString + FileString20 + vbCrLf
OutString = OutString + FileString21 + vbCrLf
OutString = OutString + FileString22
Dim s
s = IsFileInWorkspace ("SOURCE=.\res\" & _
Application.ActiveProject.Name & ".exe.Manifest")
if( s=false ) then
Documents.Add "Text"
ActiveDocument.Selection.StartOfDocument
ActiveDocument.Selection = OutString
ActiveDocument.Save "res\" & Application.ActiveProject.Name & _
".exe.Manifest"
ActiveDocument.Save
ActiveDocument.Close
ActiveProject.AddFile "res\" & Application.ActiveProject.Name & _
".exe.Manifest"
msgbox "Added " & Application.ActiveProject.Name & _
".exe.Manifest" & " into the project workspace"
end if
dim cfg
for each cfg in ActiveProject.Configurations
PrintToOutputWindow "Set manifest custom buld step for " & cfg
cfg.AddCustomBuildStep "copy $(ProjDir)\res\" & _
Application.ActiveProject.Name & _
".exe.manifest $(OutDir)\$(TargetName).exe.manifest", _
"$(OutDir)\$(TargetName).exe.manifest", "Copy manifest"
next
ExecuteCommand "WorkspaceSave"
PrintToOutputWindow "Manifest for " & _
Application.ActiveProject.Name & " generated."
MsgBox "Manifest for" & Application.ActiveProject.Name & " generated."
End Sub
Function IsFileInWorkspace(file)
Documents.Open ActiveProject.FullName, "Text", True
IsFileInWorkspace = _
ActiveDocument.Selection.FindText(file, dsMatchFromStart )
ActiveDocument.Close
End Function
I'm a french guy from Quebec, Canada. Having programmed many PLC, industrial machineries and computers in many languages at work... I'm used to program anything professionaly or just for my own fun at home. I like to learn and exchange programming techniques with others.