Updating deployment manifest for a ClickOnce application programmatically results in missing <compatibleFrameworks> element, required in 4.0

这一生的挚爱 提交于 2019-12-03 03:28:54

Figured it out myself. The culprit is ManifestReader.ReadManifest( "DeployManifest", sPathMft, true ).

MSDN says, [preserveStream argument] "specifies whether to preserve the input stream in the InputStream property of the resulting manifest object. Used by ManifestWriter to reconstitute input which is not represented in the object representation."

Wording aside, setting true is not enough by itself: dm.CompatibleFrameworks.Count will still be 0, but now the addition of CompatibleFramework items will have an effect!

For someone else in the same boat, I do that before dm.ResolveFiles( ):

if(  dm.CompatibleFrameworks.Count <= 0  )
{
    CompatibleFramework cf= new CompatibleFramework( );
    cf.Profile= "Client";       cf.Version= "4.0";      cf.SupportedRuntime=    "4.0.30319";
    dm.CompatibleFrameworks.Add( cf );              //  cf= new CompatibleFramework( );
    cf.Profile= "Full";     //  cf.Version= "4.0";      cf.SupportedRuntime=    "4.0.30319";
    dm.CompatibleFrameworks.Add( cf );              /// no need for separate object
}

@davidair, thanks for your suggestion!  Agreed, though I prefer to work with API objects (vs. XML).
Another alternative is to call mage (directly or from a .cmd file), as it seems that we are allowed to redistribute it.


I also added the following portion, which doesn't have an impact on the question itself, but may be quite important for anyone following the same path (/client is the deployment root, and can be customized):

dm.DeploymentUrl=   string.Format( "http://{0}/{1}/client/{1}.application",
                        Dns.GetHostName( ), Context.Parameters[ scTokVirtDir ] );
dm.UpdateMode=      UpdateMode.Background;
dm.UpdateUnit=      UpdateUnit.Weeks;
dm.UpdateInterval=  1;
dm.UpdateEnabled=   true;

2019-Oct-08
Just stumbled on an issue with app.manifest:
compatibility section with supportedOS elements was stripped out during deployment.

Same root cause; the line reading it should set preserveStream to true:

ApplicationManifest am = ManifestReader.ReadManifest( "ApplicationManifest", sPathMft, true ) as ApplicationManifest;

I also needed to add CompatibleFrameworks. I also tried do add the CompatibleFrameworks like this (which does not work)

dm.CompatibleFrameworks.Add(...);

My solution was to set:

dm.TargetFrameworkMoniker = ".NETFramework,Version=v4.0";                 

After this the Manifest generation was correct.

Be careful If you set the TargetFrameworkMoniker before WriteManifest you have the <compatibleFrameworks> twice and your application file is corrupt. Here is my solution for this:

DeployManifest dm = ManifestReader.ReadManifest("DeployManifest", applicationFileName, false) as DeployManifest;
dm.ResolveFiles();
//doing stuff..
dm.UpdateFileInfo();
ManifestWriter.WriteManifest(dm, applicationFileName);
dm.TargetFrameworkMoniker = ".NETFramework,Version=v4.0";
ManifestWriter.WriteManifest(dm, applicationFileName);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!