Manifest


/clr:safe    app.exe.manifest

safe つけると manifest は消える?  ==> デフォルトは出ないで正解



cl /clr test.cpp

exeを作成しtest.exe.manifestが生成される

test.rcを用意

          // text.rc 1 24 "test.exe.manifest"
       

リソース・コンパイラ 

          > rc /l400 test.


Understanding Manifest Generation for C/C++ Programs 


A manifest is an XML document that can be an external XML file or a resource embedded inside an application or an assembly.

The manifest of an isolated application is used to manage the names and versions of shared side-by-side assemblies to which the application should bind at run time.

The manifest of a side-by-side assembly specifies its dependencies on names, versions, resources, and other assemblies.

two ways to create a manifest for an isolated application or a side-by-side assembly:

manually create a manifest file

if a program only depends on Visual C++ assemblies such as CRT, MFC, ATL or others, then a manifest can be generated automatically by the linker.

The linker does not embed the manifest file inside the binary, and can only generate the manifest as an external file.

a manifest can be embedded using the manifest tool

(When building in Visual Studio, a manifest can be embedded by setting a property for the manifest tool in the Project Properties dialog; see Manifest Generation in Visual Studio.)

 


Manifest Generation at the Command Line 

the manifest is generated after the linker has processed all object files and built the final binary.

The linker collects assembly information stored in the object files and combines this information into a final manifest file.

By default the linker will generate a file named <binary_name>.<extension>.manifest to describe the final binary.

The linker does not embed a manifest file inside the binary and can only generate a manifest as an external file.

ways to embed a manifest inside the final binary:

It is important to keep in mind that specific rules have to be followed when embedding a manifest inside the final binary to enable such features as incremental linking, signing, and edit and continue.

How to: Embed a Manifest Inside a C/C++ Application 

It is recommended that a C/C++ application have its manifest embedded inside the final binary because this ensures proper runtime behavior in most scenarios.

to embed the external manifest generated by the linker as a resource inside the final binary.


# Step 1. Adding _VC_MANIFEST_INC to specify which build is incremental (1 - incremental)
# Step 2. Adding _VC_MANIFEST_BASENAME used to specify name of a temporary resource file
!if "$(DEBUG)" == "1"
CPPFLAGS=$(CPPFLAGS) /MDd
LFLAGS=$(LFLAGS) /INCREMENTAL
_VC_MANIFEST_INC=1
_VC_MANIFEST_BASENAME=__VC80.Debug

!else
CPPFLAGS=$(CPPFLAGS) /MD
_VC_MANIFEST_INC=0
_VC_MANIFEST_BASENAME=__VC80

!endif

# Step 3. Specifying name of temporary resource file used only in incremental builds

!if "$(_VC_MANIFEST_INC)" == "1"
_VC_MANIFEST_AUTO_RES=$(_VC_MANIFEST_BASENAME).auto.res
!else
_VC_MANIFEST_AUTO_RES=
!endif

#Step 4. Adding _VC_MANIFEST_EMBED_EXE - command to embedd manifest to EXE

!if "$(_VC_MANIFEST_INC)" == "1"

#MT_SPECIAL_RETURN=1090650113
#MT_SPECIAL_SWITCH=-notify_resource_update
MT_SPECIAL_RETURN=0
MT_SPECIAL_SWITCH=
_VC_MANIFEST_EMBED_EXE= \
if exist $@.manifest mt.exe -manifest $@.manifest -out:$(_VC_MANIFEST_BASENAME).auto.manifest $(MT_SPECIAL_SWITCH) & \
if "%ERRORLEVEL%" == "$(MT_SPECIAL_RETURN)" \
rc /r $(_VC_MANIFEST_BASENAME).auto.rc & \
link $** /out:$@ $(LFLAGS)

!else

_VC_MANIFEST_EMBED_EXE= \
if exist $@.manifest mt.exe -manifest $@.manifest -outputresource:$@;1

!endif

# Step 5. Changing command used to build EXE
MyApplication.exe : MyApplication.obj $(_VC_MANIFEST_AUTO_RES)
link $** /out:$@ $(LFLAGS)
$(_VC_MANIFEST_EMBED_EXE)


MyApplication.obj : MyApplication.cpp

# Step 6. Adding commands to generate initial empty manifest file, RC file
#         that references it and for generating the .res file

$(_VC_MANIFEST_BASENAME).auto.res : $(_VC_MANIFEST_BASENAME).auto.rc

$(_VC_MANIFEST_BASENAME).auto.rc : $(_VC_MANIFEST_BASENAME).auto.manifest
type <<$@
#include <winuser.h>
1RT_MANIFEST"$(_VC_MANIFEST_BASENAME).auto.manifest"
<< KEEP

$(_VC_MANIFEST_BASENAME).auto.manifest :
type <<$@
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
</assembly>
<< KEEP

# Step 7. Adding _VC_MANIFEST_CLEAN - command to clean generate files 
#         for temporary resources
!if "$(_VC_MANIFEST_INC)" == "1"

_VC_MANIFEST_CLEAN=-del $(_VC_MANIFEST_BASENAME).auto.res \
    $(_VC_MANIFEST_BASENAME).auto.rc \
    $(_VC_MANIFEST_BASENAME).auto.manifest

!else

_VC_MANIFEST_CLEAN=

!endif

clean : 
del MyApplication.obj MyApplication.exe MyApplication.exe.manifest
$(_VC_MANIFEST_CLEAN)