Esempio n. 1
0
        private void ValidateGeneratedProject(
            string[] itemsToSign,
            Dictionary <string, SignInfo> strongNameSignInfo,
            Dictionary <ExplicitCertificateKey, string> fileSignInfo,
            Dictionary <string, SignInfo> extensionsSignInfo,
            string[] expectedXmlElementsPerSingingRound,
            string[] dualCertificates = null)
        {
            var buildEngine = new FakeBuildEngine();

            var task = new SignToolTask {
                BuildEngine = buildEngine
            };

            // The path to MSBuild will always be null in these tests, this will force
            // the signing logic to call our FakeBuildEngine.BuildProjectFile with a path
            // to the XML that store the content of the would be Microbuild sign request.
            var signToolArgs = new SignToolArgs(_tmpDir, microBuildCorePath: "MicroBuildCorePath", testSign: true, msBuildPath: null, _tmpDir, enclosingDir: "", "");

            var signTool     = new FakeSignTool(signToolArgs, task.Log);
            var signingInput = new Configuration(signToolArgs.TempDir, itemsToSign, strongNameSignInfo, fileSignInfo, extensionsSignInfo, dualCertificates, task.Log).GenerateListOfFiles();
            var util         = new BatchSignUtil(task.BuildEngine, task.Log, signTool, signingInput, new string[] { });

            util.Go(false);

            Assert.Same(ByteSequenceComparer.Instance, signingInput.ZipDataMap.KeyComparer);

            // The list of files that would be signed was captured inside the FakeBuildEngine,
            // here we check if that matches what we expected
            var actualXmlElementsPerSingingRound = buildEngine.FilesToSign.Select(round => string.Join(Environment.NewLine, round));

            AssertEx.Equal(expectedXmlElementsPerSingingRound, actualXmlElementsPerSingingRound, comparer: AssertEx.EqualIgnoringWhitespace, itemInspector: s => s.Replace("\"", "\"\""));

            Assert.False(task.Log.HasLoggedErrors);
        }
Esempio n. 2
0
        public bool BuildProjectFile(string projectFileName, string[] targetNames, IDictionary globalProperties, IDictionary targetOutputs)
        {
            var xml = XDocument.Load(projectFileName);

            var itemGroupNode = xml.Descendants("ItemGroup");

            if (itemGroupNode.Count() == 0)
            {
                LogErrorEvent(new BuildErrorEventArgs(string.Empty, string.Empty, string.Empty, 0, 0, 0, 0, "Didn't find a project node.", "", ""));
                return(false);
            }
            else if (itemGroupNode.Count() > 1)
            {
                LogErrorEvent(new BuildErrorEventArgs(string.Empty, string.Empty, string.Empty, 0, 0, 0, 0, "Only one <ItemGroup> is expected on this file.", "", ""));
                return(false);
            }
            else
            {
                var filesToSign = itemGroupNode.Descendants("FilesToSign").ToImmutableArray();
                FilesToSign.Add(filesToSign);

                foreach (var file in filesToSign)
                {
                    FakeSignTool.SignFile(file.Attribute("Include").Value);
                }

                return(true);
            }
        }