public override bool Execute()
        {
            TrustInfo info = new TrustInfo {
                IsFullTrust = false
            };
            FrameworkName name = null;
            string        str  = string.Empty;

            if (!string.IsNullOrEmpty(this.TargetFrameworkMoniker))
            {
                name = new FrameworkName(this.TargetFrameworkMoniker);
                str  = name.Version.ToString();
            }
            if ((this.BaseManifest != null) && File.Exists(this.BaseManifest.ItemSpec))
            {
                try
                {
                    info.ReadManifest(this.BaseManifest.ItemSpec);
                }
                catch (Exception exception)
                {
                    base.Log.LogErrorWithCodeFromResources("GenerateManifest.ReadInputManifestFailed", new object[] { this.BaseManifest.ItemSpec, exception.Message });
                    return(false);
                }
            }
            if (!string.IsNullOrEmpty(this.ExcludedPermissions))
            {
                base.Log.LogWarningFromResources("GenerateManifest.ExcludedPermissionsNotSupported", new object[0]);
            }
            try
            {
                if ((!string.IsNullOrEmpty(this.targetZone) && (info.PermissionSet != null)) && ((info.PermissionSet.Count > 0) && !string.Equals(this.targetZone, "Custom", StringComparison.OrdinalIgnoreCase)))
                {
                    base.Log.LogErrorFromResources("GenerateManifest.KnownTargetZoneCannotHaveAdditionalPermissionType", new object[0]);
                    return(false);
                }
                info.PermissionSet = SecurityUtilities.ComputeZonePermissionSetHelper(this.TargetZone, info.PermissionSet, this.applicationDependencies, this.TargetFrameworkMoniker);
                if (info.PermissionSet == null)
                {
                    base.Log.LogErrorWithCodeFromResources("GenerateManifest.NoPermissionSetForTargetZone", new object[] { str });
                    return(false);
                }
            }
            catch (ArgumentNullException)
            {
                base.Log.LogErrorWithCodeFromResources("GenerateManifest.NoPermissionSetForTargetZone", new object[] { str });
                return(false);
            }
            catch (ArgumentException exception2)
            {
                if (!string.Equals(exception2.ParamName, "TargetZone", StringComparison.OrdinalIgnoreCase))
                {
                    throw;
                }
                base.Log.LogWarningWithCodeFromResources("GenerateManifest.InvalidItemValue", new object[] { "TargetZone", this.TargetZone });
            }
            info.Write(this.TrustInfoFile.ItemSpec);
            return(true);
        }
Exemplo n.º 2
0
        public override bool Execute()
        {
            var trustInfo = new TrustInfo {
                IsFullTrust = false
            };
            string dotNetVersion = string.Empty;

            if (!string.IsNullOrEmpty(TargetFrameworkMoniker))
            {
                var fn = new FrameworkNameVersioning(TargetFrameworkMoniker);
                dotNetVersion = fn.Version.ToString();
            }

            // Read trust-info from app.manifest
            if (BaseManifest != null && File.Exists(BaseManifest.ItemSpec))
            {
                try
                {
                    trustInfo.ReadManifest(BaseManifest.ItemSpec);
                }
                catch (Exception ex)
                {
                    Log.LogErrorWithCodeFromResources("GenerateManifest.ReadInputManifestFailed", BaseManifest.ItemSpec, ex.Message);
                    return(false);
                }
            }

            if (!String.IsNullOrEmpty(ExcludedPermissions))
            {
                Log.LogWarningFromResources("GenerateManifest.ExcludedPermissionsNotSupported");
            }

            try
            {
                // If it's a known zone and the user add additional permission to it.
                if (!String.IsNullOrEmpty(TargetZone) &&
                    trustInfo.PermissionSet != null && trustInfo.PermissionSet.Count > 0 &&
                    !String.Equals(TargetZone, Custom, StringComparison.OrdinalIgnoreCase))
                {
                    Log.LogErrorFromResources("GenerateManifest.KnownTargetZoneCannotHaveAdditionalPermissionType");
                    return(false);
                }
                else
                {
                    trustInfo.PermissionSet = SecurityUtilities.ComputeZonePermissionSetHelper(TargetZone, trustInfo.PermissionSet, ApplicationDependencies, TargetFrameworkMoniker);
                    if (trustInfo.PermissionSet == null)
                    {
                        Log.LogErrorWithCodeFromResources("GenerateManifest.NoPermissionSetForTargetZone", dotNetVersion);
                        return(false);
                    }
                }
            }
            catch (ArgumentNullException)
            {
                Log.LogErrorWithCodeFromResources("GenerateManifest.NoPermissionSetForTargetZone", dotNetVersion);
                return(false);
            }
            catch (ArgumentException ex)
            {
                if (String.Equals(ex.ParamName, "TargetZone", StringComparison.OrdinalIgnoreCase))
                {
                    Log.LogWarningWithCodeFromResources("GenerateManifest.InvalidItemValue", "TargetZone", TargetZone);
                }
                else
                {
                    throw;
                }
            }

            // Write trust-info back to a stand-alone trust file
            trustInfo.Write(TrustInfoFile.ItemSpec);

            return(true);
        }