public static ITaskItem CreateFileItem(string sourcePath, string targetPath, string targetFramework)
 {
     TaskItem item = new TaskItem(sourcePath);
     item.SetMetadata("TargetPath", targetPath);
     item.SetMetadata("TargetFramework", targetFramework);
     return item;
 }
Beispiel #2
0
        public override bool Execute()
        {
            ArrayList list = new ArrayList();
            foreach (ITaskItem item in AssemblyFiles)
            {
                AssemblyName an;
                try
                {
                    an = AssemblyName.GetAssemblyName(item.ItemSpec);
                }
                catch (BadImageFormatException e)
                {
                    Log.LogErrorWithCodeFromResources("GetAssemblyIdentity.CouldNotGetAssemblyName", item.ItemSpec, e.Message);
                    continue;
                }
                catch (Exception e) when (ExceptionHandling.IsIoRelatedException(e))
                {
                    Log.LogErrorWithCodeFromResources("GetAssemblyIdentity.CouldNotGetAssemblyName", item.ItemSpec, e.Message);
                    continue;
                }

                ITaskItem newItem = new TaskItem(an.FullName);
                newItem.SetMetadata("Name", an.Name);
                if (an.Version != null)
                    newItem.SetMetadata("Version", an.Version.ToString());
                if (an.GetPublicKeyToken() != null)
                    newItem.SetMetadata("PublicKeyToken", ByteArrayToHex(an.GetPublicKeyToken()));
                if (an.CultureInfo != null)
                    newItem.SetMetadata("Culture", an.CultureInfo.ToString());
                item.CopyMetadataTo(newItem);
                list.Add(newItem);
            }
            Assemblies = (ITaskItem[])list.ToArray(typeof(ITaskItem));
            return !Log.HasLoggedErrors;
        }
Beispiel #3
0
 /// <summary>
 /// Helper function to parse the ParameterEntryElement
 /// </summary>
 /// <param name="element"></param>
 /// <param name="parentItem"></param>
 /// <returns></returns>
 private Utilities.TaskItem ReadParameterEntryElement(Xml.XmlElement element, Utilities.TaskItem parentItem)
 {
     Debug.Assert(element != null && parentItem != null);
     Utilities.TaskItem taskItem = null;
     if (string.Compare(element.Name, "parameterEntry", System.StringComparison.OrdinalIgnoreCase) == 0)
     {
         taskItem = new Microsoft.Build.Utilities.TaskItem(parentItem);
         taskItem.RemoveMetadata("OriginalItemSpec");
         foreach (Xml.XmlNode attribute in element.Attributes)
         {
             if (attribute != null && attribute.Name != null && attribute.Value != null)
             {
                 string value = DisableEscapeMSBuildVariable ? attribute.Value : Utility.EscapeTextForMSBuildVariable(attribute.Value);
                 taskItem.SetMetadata(attribute.Name, value);
             }
         }
     }
     else if (string.Compare(element.Name, "parameterValidation", System.StringComparison.OrdinalIgnoreCase) == 0)
     {
         taskItem = new Microsoft.Build.Utilities.TaskItem(parentItem);
         taskItem.RemoveMetadata("OriginalItemSpec");
         taskItem.SetMetadata("Element", "parameterValidation");
         foreach (Xml.XmlNode attribute in element.Attributes)
         {
             if (attribute != null && attribute.Name != null && attribute.Value != null)
             {
                 string value = DisableEscapeMSBuildVariable ? attribute.Value : Utility.EscapeTextForMSBuildVariable(attribute.Value);
                 taskItem.SetMetadata(attribute.Name, value);
             }
         }
     }
     return(taskItem);
 }
        private static void ResolveSDKFromRefereneAssemblyLocation(string referenceName, string expectedPath)
        {
            // Create the engine.
            MockEngine engine = new MockEngine();
            TaskItem taskItem = new TaskItem(referenceName);
            taskItem.SetMetadata("SDKName", "FakeSDK, Version=1.0");

            TaskItem resolvedSDK = new TaskItem(@"C:\FakeSDK");
            resolvedSDK.SetMetadata("SDKName", "FakeSDK, Version=1.0");
            resolvedSDK.SetMetadata("TargetedSDKConfiguration", "Debug");
            resolvedSDK.SetMetadata("TargetedSDKArchitecture", "X86");

            TaskItem[] assemblies = new TaskItem[] { taskItem };

            // Now, pass feed resolved primary references into ResolveAssemblyReference.
            ResolveAssemblyReference t = new ResolveAssemblyReference();

            t.BuildEngine = engine;
            t.Assemblies = assemblies;
            t.ResolvedSDKReferences = new ITaskItem[] { resolvedSDK };
            t.SearchPaths = new String[] { @"C:\SomeOtherPlace" };
            bool succeeded = Execute(t);

            Assert.True(succeeded);
            Assert.Equal(1, t.ResolvedFiles.Length);
            Assert.Equal(0, engine.Errors);
            Assert.Equal(0, engine.Warnings);
            Assert.True(t.ResolvedFiles[0].ItemSpec.Equals(expectedPath, StringComparison.OrdinalIgnoreCase));
        }
        public void Build()
        {
            RegexCompiler task = new RegexCompiler();
            task.BuildEngine = new MockBuild();
            task.OutputDirectory = TaskUtility.TestDirectory;
            task.AssemblyName = "MSBuild.Community.RegularExpressions.dll";
            task.AssemblyTitle = "MSBuild.Community.RegularExpressions";
            task.AssemblyDescription = "MSBuild Community Tasks Regular Expressions";
            task.AssemblyCompany = "MSBuildTasks";
            task.AssemblyProduct = "MSBuildTasks";
            task.AssemblyCopyright = "Copyright (c) MSBuildTasks 2008";
            task.AssemblyVersion = "1.0.0.0";
            task.AssemblyFileVersion = "1.0.0.0";
            task.AssemblyInformationalVersion = "1.0.0.0";
            task.AssemblyKeyFile = @"..\..\..\MSBuild.Community.Tasks\MSBuild.Community.Tasks.snk";

            List<ITaskItem> expressions = new List<ITaskItem>();

            TaskItem item1 = new TaskItem("TextRegex");
            item1.SetMetadata("Pattern", @"\G[^<]+");
            item1.SetMetadata("Options", "RegexOptions.Singleline | RegexOptions.Multiline");
            item1.SetMetadata("IsPublic", "true");

            TaskItem item2 = new TaskItem("CommentRegex");
            item2.SetMetadata("Pattern", @"\G<%--(([^-]*)-)*?-%>");
            item2.SetMetadata("Options", "RegexOptions.Singleline | RegexOptions.Multiline");
            item2.SetMetadata("IsPublic", "true");

            task.RegularExpressions = new ITaskItem[] {item1, item2};

            bool result = task.Execute();
            Assert.IsTrue(result);
        }
Beispiel #6
0
		public override bool Execute ()
		{
			assemblies = new ITaskItem [assembly_files.Length];

			for (int i = 0; i < assemblies.Length; i++) {
				string file = assembly_files [i].ItemSpec;
				AssemblyName an = AssemblyName.GetAssemblyName (file);
				TaskItem item = new TaskItem (an.FullName);

				item.SetMetadata ("Version", an.Version.ToString ());

				byte[] pk = an.GetPublicKeyToken ();
				string pkStr = pk != null? ByteArrayToString (pk) : "null";
				item.SetMetadata ("PublicKeyToken", pkStr);

				CultureInfo culture = an.CultureInfo;
				if (culture != null) {
					string cn;
					if (culture.LCID == CultureInfo.InvariantCulture.LCID)
						cn = "neutral";
					else
						cn = culture.Name;
					item.SetMetadata ("Culture", cn);
				}

				assemblies[i] = item;
			}

			return true;
		}
        public override bool Execute()
        {
            Regex packageNameRegex = new Regex(PackageNameRegex);
            List<ITaskItem> packageNameItems = new List<ITaskItem>();

            foreach (string packageDrop in PackageDrops)
            {
                if (!Directory.Exists(packageDrop))
                {
                    Log.LogWarning("PackageDrop does not exist - '{0}'", packageDrop);
                    continue;
                }
                IEnumerable<ITaskItem> packages = Directory.GetFiles(packageDrop).Select(f => new TaskItem(Path.GetFileNameWithoutExtension(f)));


                foreach (ITaskItem package in packages)
                {
                    Match m = packageNameRegex.Match(package.ItemSpec);
                    if (m.Success)
                    {
                        TaskItem packageName = new TaskItem(m.Groups[0].Value);
                        packageName.SetMetadata("PackageName", m.Groups[1].Value);
                        packageName.SetMetadata("PackageVersion", m.Groups[2].Value);
                        packageName.SetMetadata("PrereleaseVersion", m.Groups[3].Value);
                        packageNameItems.Add(packageName);
                    }
                }
            }
            PackageNames = packageNameItems?.OrderBy(an => an.ItemSpec.ToString(), StringComparer.Ordinal)?.ToArray();
            return true;
        }
        public void AppendItemWithMissingAttribute()
        {
            // Construct the task items.
            TaskItem i = new TaskItem();
            i.ItemSpec = "MySoundEffect.wav";
            i.SetMetadata("Name", "Kenny");
            i.SetMetadata("Access", "Private");

            TaskItem j = new TaskItem();
            j.ItemSpec = "MySplashScreen.bmp";
            j.SetMetadata("Name", "Cartman");
            j.SetMetadata("HintPath", @"c:\foo");
            j.SetMetadata("Access", "Public");

            CommandLineBuilderExtension c = new CommandLineBuilderExtension();

            c.AppendSwitchIfNotNull
            (
                "/myswitch:",
                new ITaskItem[] { i, j },
                new string[] { "Name", "HintPath", "Access" },
                null
            );
            Assert.Equal(@"/myswitch:MySoundEffect.wav,Kenny /myswitch:MySplashScreen.bmp,Cartman,c:\foo,Public", c.ToString());
        }
        public static ITaskItem CreateDependencyItem(string sourcePath, string version, string targetFramework)
        {
            TaskItem item = new TaskItem(sourcePath);

            if (version != null)
            {
                item.SetMetadata("Version", version);
            }

            item.SetMetadata("TargetFramework", targetFramework);
            return item;
        }
        /*
         * Method:  SetupTaskItem
         * 
         * Creates a valid task item that's modified later
         */
        private TaskItem SetupTaskItem()
        {
            TaskItem item = new TaskItem();

            item.SetMetadata(ComReferenceItemMetadataNames.guid, "{5C6D0C4D-D530-4B08-B22F-307CA6BFCB65}");
            item.SetMetadata(ComReferenceItemMetadataNames.versionMajor, "1");
            item.SetMetadata(ComReferenceItemMetadataNames.versionMinor, "0");
            item.SetMetadata(ComReferenceItemMetadataNames.lcid, "0");
            item.SetMetadata(ComReferenceItemMetadataNames.wrapperTool, "tlbimp");

            return item;
        }
            public TaskItem ToTaskItem()
            {
                var item = new TaskItem(OutputFilePath);

                // For Fxo we output Link used by <Content> Item
                if (!OutputCs)
                {
                    item.SetMetadata("CopyToOutputDirectory", "PreserveNewest");
                    item.SetMetadata("Link", OutputLink);
                }
                return item;
            }
        public override bool Execute()
        {
            if (Assemblies == null || Assemblies.Length == 0)
                return true;

            List<ITaskItem> references = new List<ITaskItem>();
            List<ITaskItem> nativeLibs = new List<ITaskItem>();

            foreach (var assemblyItem in Assemblies)
            {
                try
                {
                    if (!File.Exists(assemblyItem.ItemSpec))
                    {
                        Log.LogError($"File {assemblyItem.ItemSpec} does not exist, ensure you have built libraries before building the package.");
                        continue;
                    }

                    using (PEReader peReader = new PEReader(new FileStream(assemblyItem.ItemSpec, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.Read)))
                    {
                        MetadataReader reader = peReader.GetMetadataReader();
                        foreach (var handle in reader.AssemblyReferences)
                        {
                            AssemblyReference reference = reader.GetAssemblyReference(handle);
                            TaskItem referenceItem = new TaskItem(reader.GetString(reference.Name));
                            assemblyItem.CopyMetadataTo(referenceItem);
                            referenceItem.SetMetadata("Version", reference.Version.ToString());
                            referenceItem.SetMetadata("AssemblyVersion", reference.Version.ToString());
                            references.Add(referenceItem);
                        }

                        for (int i = 1, count = reader.GetTableRowCount(TableIndex.ModuleRef); i <= count; i++)
                        {
                            var moduleRef = reader.GetModuleReference(MetadataTokens.ModuleReferenceHandle(i));
                            var moduleName = reader.GetString(moduleRef.Name);

                            TaskItem nativeLib = new TaskItem(moduleName);
                            assemblyItem.CopyMetadataTo(nativeLib);
                            nativeLibs.Add(nativeLib);
                        }
                    }
                }
                catch (InvalidOperationException)
                {
                    // Ignore invalid assemblies
                }
            }

            ReferencedAssemblies = references.ToArray();
            ReferencedNativeLibraries = nativeLibs.ToArray();

            return true;
        }
        static internal ITaskItem CreateReferenceItem(string itemSpec, string projectGuid, string package, string name)
        {
            TaskItem reference = new TaskItem(itemSpec);

            if (projectGuid != null)
                reference.SetMetadata(attributeProject, projectGuid);
            if (package != null)
                reference.SetMetadata("Package", package);
            if (name != null)
                reference.SetMetadata("Name", name);

            return reference;
        }
Beispiel #14
0
        public override bool Execute()
        {
            var artworkWithLogicalNames = new List<ITaskItem> ();
            var artwork = new HashSet<string> ();

            Log.LogTaskName ("CollectITunesArtwork");
            Log.LogTaskProperty ("ITunesArtwork", ITunesArtwork);

            if (ITunesArtwork != null) {
                foreach (var item in ITunesArtwork) {
                    // We need a physical path here, ignore the Link element
                    var path = item.GetMetadata ("FullPath");
                    string logicalName;
                    int width, height;

                    if (!File.Exists (path)) {
                        Log.LogError ("  '{0}' not found.", path);
                        continue;
                    }

                    if (!GetPngImageSize (path, out width, out height) && !GetJpgImageSize (path, out width, out height)) {
                        Log.LogError (null, null, null, path, 0, 0, 0, 0, "Error loading '{0}': Unknown image format.", path);
                        return false;
                    }

                    if (width != height || (width != 512 && width != 1024)) {
                        Log.LogError (null, null, null, path, 0, 0, 0, 0, "Invalid iTunesArtwork dimensions ({0}x{1}) for '{2}'.", width, height, path);
                        return false;
                    }

                    logicalName = width == 1024 ? "iTunesArtwork@2x" : "iTunesArtwork";

                    if (!artwork.Add (logicalName)) {
                        Log.LogError (null, null, null, path, 0, 0, 0, 0, "Multiple iTunesArtwork files with the same dimensions detected.");
                        return false;
                    }

                    var bundleResource = new TaskItem (item);
                    bundleResource.SetMetadata ("LogicalName", logicalName);
                    bundleResource.SetMetadata ("Optimize", "false");

                    artworkWithLogicalNames.Add (bundleResource);
                }
            }

            ITunesArtworkWithLogicalNames = artworkWithLogicalNames.ToArray ();

            return !Log.HasLoggedErrors;
        }
        public override bool Execute()
        {
            // read the xml file and populate the JobsFound result

            if (File.Exists(ConfigFile)) {

                var doc = XDocument.Load(ConfigFile);
                var jobs = from wj in doc.Root.Elements("WebJob")
                           select new {
                               RelPath = wj.Attribute("RelativePath").Value,
                               Schedule = wj.Attribute("Schedule").Value
                           };

                var resultList = new List<ITaskItem>();

                foreach (var job in jobs) {

                    var item = new TaskItem(job.RelPath);
                    item.SetMetadata("Schedule", job.Schedule);

                    resultList.Add(item);
                }

                JobsFound = resultList.ToArray();
            }
            else {
                Log.LogMessage("web jobs config file not found at [{0}]", ConfigFile);
            }

            return !Log.HasLoggedErrors;
        }
Beispiel #16
0
 private static ITaskItem CreateProjectCopyLocal(ProjectCopyLocal projectCopyLocal)
 {
     var copies = projectCopyLocal.CopyLocals;
     var result = new TaskItem(projectCopyLocal.Project);
     result.SetMetadata("CopyLocals", string.Join(Environment.NewLine, copies.ToArray()));    
     return result;
 }
        private static ITaskItem[] GetSourceFolder(string folder)
        {
            var folderItem = new TaskItem(folder);
            folderItem.SetMetadata("Test-name", "Test-Content");

            return new ITaskItem[] { folderItem };
        }
Beispiel #18
0
        public override bool Execute()
        {
            var results = new List<ITaskItem> ();

            Log.LogTaskName ("PackLibraryResources");
            Log.LogTaskProperty ("BundleResourcesWithLogicalNames", BundleResourcesWithLogicalNames);
            Log.LogTaskProperty ("Prefix", Prefix);

            if (BundleResourcesWithLogicalNames != null) {
                foreach (var item in BundleResourcesWithLogicalNames) {
                    var logicalName = item.GetMetadata ("LogicalName");

                    if (string.IsNullOrEmpty (logicalName)) {
                        Log.LogError ("Items must have logical names computed.");
                        return false;
                    }

                    var embedded = new TaskItem (item);

                    embedded.SetMetadata ("LogicalName", "__" + Prefix + "_content_" + EscapeMangledResource (logicalName));

                    results.Add (embedded);
                }
            }

            EmbeddedResources = results.ToArray ();

            return !Log.HasLoggedErrors;
        }
Beispiel #19
0
		public override bool Execute ()
		{
			if (files == null || files.Length == 0)
				//nothing to do
				return true;

			List<ITaskItem> outFiles = new List<ITaskItem> ();

			for (int i = 0; i < files.Length; i ++) {
				string file = files [i].ItemSpec;
				string link = files [i].GetMetadata ("Link");
				string definingProjectPath = files [i].GetMetadata ("DefiningProjectFullPath");

				if (String.IsNullOrEmpty (link) && Path.IsPathRooted (file) && !string.IsNullOrEmpty (definingProjectPath)) {
					file = Path.GetFullPath (file);
					var projectDir = Path.GetFullPath (Path.GetDirectoryName (definingProjectPath));
					if (projectDir.Length == 0 || projectDir [projectDir.Length - 1] != Path.DirectorySeparatorChar)
						projectDir += Path.DirectorySeparatorChar;
					if (file.StartsWith (projectDir)) {
						// The file is in the same folder or a subfolder of the project that contains it.
						// Use the relative path wrt the containing project as link.
						var outFile = new TaskItem (files [i]);
						outFile.SetMetadata ("Link", file.Substring (projectDir.Length));
						outFiles.Add (outFile);
					}
				}
			}

			assignedFiles = outFiles.ToArray ();

			return true;
		}
 public override bool Execute()
 {
     if (string.IsNullOrEmpty(SourceDirectory))
     {
         Log.LogError("Argument SourceDirectory is missing.");
         return false;
     }
     if (string.IsNullOrEmpty(StartAppPath))
     {
         Log.LogError("Argument StartAppPath is missing.");
         return false;
     }
     if (string.IsNullOrEmpty(UniqueSourceDirectoryPath))
     {
         Log.LogError("Argument UniqueSourceDirectoryPath is missing.");
         return false;
     }
     var orderer = new AppOrderer();
     var list = orderer.GetAppBuildOrder(SourceDirectory, StartAppPath, UniqueSourceDirectoryPath, Log);
     var returnList = new List<ITaskItem>();
     foreach (string app in list)
     {
         ITaskItem item = new TaskItem(app);
         item.SetMetadata("AppPath", app);
         returnList.Add(item);
     }
     AppList = returnList.ToArray();
     return true;
 }
Beispiel #21
0
        public override bool Execute()
        {
            EmbeddedResources = new ITaskItem[BundleResources.Length];

            Log.LogTaskName ("CreateEmbeddedResources");
            Log.LogTaskProperty ("BundleResources", BundleResources);
            Log.LogTaskProperty ("Prefix", Prefix);

            for (int i = 0; i < BundleResources.Length; i++) {
                var bundleResource = BundleResources[i];

                // clone the item
                var embeddedResource = new TaskItem (bundleResource.ItemSpec);
                bundleResource.CopyMetadataTo (embeddedResource);

                // mangle the resource name
                var logicalName = "__" + Prefix + "_content_" + EscapeMangledResource (bundleResource.GetMetadata ("LogicalName"));
                embeddedResource.SetMetadata ("LogicalName", logicalName);

                // add it to the output connection
                EmbeddedResources[i] = embeddedResource;
            }

            return true;
        }
		private void SetMetaData(TaskItem item, string data, bool set)
		{
			if (set)
			{
				item.SetMetadata(TemplateFile.MetadataValueTag, data);
			}
		}
        private ITaskItem ComputeLocalizedResource(ITaskItem xlf)
        {
            var resxName = xlf.GetMetadata("FileName");
            var resxFileName = resxName + ".resx";
            var resxPath = Path.Combine(LocalizedResxRoot, resxFileName);

            var resxItem = new TaskItem(resxPath);
            resxItem.SetMetadata(NeutralResxMetadata, xlf.GetMetadata(NeutralResxMetadata));
            resxItem.SetMetadata(ParentXlfMetadata, xlf.ItemSpec);
            resxItem.SetMetadata(ComputedCultureCodeMetadata, xlf.GetMetadata(ComputedCultureCodeMetadata));
            resxItem.SetMetadata(LogicalNameMetadata, $"{AssemblyName}.{resxName}.resources");

            xlf.SetMetadata(ChildResxMetadata, resxPath);

            return resxItem;
        }
Beispiel #24
0
 public void CheckForSpecificMetadataOnParent()
 {
     Reference reference = new Reference(isWinMDFile, fileExists, getRuntimeVersion);
     ITaskItem taskItem = new TaskItem("TestReference");
     taskItem.SetMetadata("SpecificVersion", "true");
     reference.MakePrimaryAssemblyReference(taskItem, true, ".dll");
     Assert.True(reference.CheckForSpecificVersionMetadataOnParentsReference(false));
 }
        private ITaskItem CreateScriptItem(FileInfo arg)
        {
            var item = new TaskItem(arg.FullName);

            item.SetMetadata("Schema", arg.Directory.Name);

            return item;
        }
Beispiel #26
0
        public override bool Execute()
        {
            Log.LogTaskName ("PrepareNativeReferences");
            Log.LogTaskProperty ("IntermediateOutputPath", IntermediateOutputPath);
            Log.LogTaskProperty ("NativeReferences", NativeReferences);

            if (NativeReferences == null || NativeReferences.Length == 0)
                return !Log.HasLoggedErrors;

            var embeddedResources = new List<ITaskItem> ();
            var nativeFrameworks = new List<ITaskItem> ();
            var text = new StringBuilder ();

            for (int i = 0; i < NativeReferences.Length; i++) {
                NativeReferenceKind kind;
                string value;

                value = NativeReferences[i].GetMetadata ("Kind") ?? string.Empty;
                if (!Enum.TryParse (value, out kind)) {
                    Log.LogError (null, null, null, NativeReferences[i].ItemSpec, 0, 0, 0, 0, "Unknown native reference type: {0}", value);
                    continue;
                }

                var path = NativeReferences[i].ItemSpec;
                var logicalName = Path.GetFileName (path);

                var item = new TaskItem (path);

                if (kind == NativeReferenceKind.Framework) {
                    nativeFrameworks.Add (item);
                } else {
                    item.SetMetadata ("LogicalName", logicalName);
                    embeddedResources.Add (item);
                }

                text.AppendFormat ("[assembly: ObjCRuntime.LinkWith (\"{0}\"", logicalName);
                AppendLinkTargetProperty (text, NativeReferences[i]);
                AppendBooleanProperty (text, NativeReferences[i], "IsCxx");
                AppendBooleanProperty (text, NativeReferences[i], "NeedsGccExceptionHandling");
                AppendBooleanProperty (text, NativeReferences[i], "SmartLink", true);
                AppendBooleanProperty (text, NativeReferences[i], "ForceLoad");
                AppendStringProperty (text, NativeReferences[i], "Frameworks");
                AppendStringProperty (text, NativeReferences[i], "WeakFrameworks");
                AppendStringProperty (text, NativeReferences[i], "LinkerFlags");
                text.Append (")]");
                text.AppendLine ();
            }

            var linkWith = Path.Combine (IntermediateOutputPath, "LinkWithAttributes.cs");
            Directory.CreateDirectory (Path.GetDirectoryName (linkWith));
            File.WriteAllText (linkWith, text.ToString ());

            EmbeddedResources = embeddedResources.ToArray ();
            NativeFrameworks = nativeFrameworks.ToArray ();
            LinkWithAttributes = new TaskItem (linkWith);

            return !Log.HasLoggedErrors;
        }
Beispiel #27
0
        protected ITaskItem ConvertPackageElement(ITaskItem project, PackageReference packageReference)
        {
            var id = packageReference.Id;
            var version = packageReference.Version;
            var targetFramework = packageReference.TargetFramework;
            var isDevelopmentDependency = packageReference.IsDevelopmentDependency;
            var requireReinstallation = packageReference.RequireReinstallation;
            var versionConstraint = packageReference.VersionConstraint;

            var item = new TaskItem(id);
            project.CopyMetadataTo(item);

            var packageDirectoryPath = GetPackageDirectoryPath(project.GetMetadata("FullPath"), id, version);
            item.SetMetadata("PackageDirectoryPath", packageDirectoryPath);
            item.SetMetadata("ProjectPath", project.GetMetadata("FullPath"));

            item.SetMetadata("IsDevelopmentDependency", isDevelopmentDependency.ToString());
            item.SetMetadata("RequireReinstallation", requireReinstallation.ToString());

            if (version != null)
                item.SetMetadata(Metadata.Version, version.ToString());

            if (targetFramework != null)
                item.SetMetadata(Metadata.TargetFramework, targetFramework.GetShortFrameworkName());

            if (versionConstraint != null)
                item.SetMetadata("VersionConstraint", versionConstraint.ToString());

            return item;
        }
 public override bool Execute()
 {
     ArrayList list = new ArrayList();
     foreach (ITaskItem item in this.AssemblyFiles)
     {
         AssemblyName assemblyName;
         try
         {
             assemblyName = AssemblyName.GetAssemblyName(item.ItemSpec);
         }
         catch (BadImageFormatException exception)
         {
             base.Log.LogErrorWithCodeFromResources("GetAssemblyIdentity.CouldNotGetAssemblyName", new object[] { item.ItemSpec, exception.Message });
             continue;
         }
         catch (Exception exception2)
         {
             if (Microsoft.Build.Shared.ExceptionHandling.NotExpectedException(exception2))
             {
                 throw;
             }
             base.Log.LogErrorWithCodeFromResources("GetAssemblyIdentity.CouldNotGetAssemblyName", new object[] { item.ItemSpec, exception2.Message });
             continue;
         }
         ITaskItem destinationItem = new TaskItem(assemblyName.FullName);
         destinationItem.SetMetadata("Name", assemblyName.Name);
         if (assemblyName.Version != null)
         {
             destinationItem.SetMetadata("Version", assemblyName.Version.ToString());
         }
         if (assemblyName.GetPublicKeyToken() != null)
         {
             destinationItem.SetMetadata("PublicKeyToken", ByteArrayToHex(assemblyName.GetPublicKeyToken()));
         }
         if (assemblyName.CultureInfo != null)
         {
             destinationItem.SetMetadata("Culture", assemblyName.CultureInfo.ToString());
         }
         item.CopyMetadataTo(destinationItem);
         list.Add(destinationItem);
     }
     this.Assemblies = (ITaskItem[]) list.ToArray(typeof(ITaskItem));
     return !base.Log.HasLoggedErrors;
 }
Beispiel #29
0
        public void References()
        {
            Vbc t = new Vbc();

            TaskItem reference = new TaskItem("System.Xml.dll");
            reference.SetMetadata("Alias", "Foo");

            t.References = new TaskItem[] { reference };
            CommandLine.ValidateHasParameter(t, "/reference:System.Xml.dll");
        }
        public override bool Execute()
        {
            // for each marker file, deserialize the JSON data and convert it to a task item
            var signTypeItems = new List<Tuple<string, SignTypeItem>>();

            foreach (var markerFile in MarkerFiles)
            {
                if (!File.Exists(markerFile.ItemSpec))
                {
                    Log.LogError("The specified marker file '{0}' doesn't exist.", markerFile.ItemSpec);
                    return false;
                }

                using (var streamReader = new StreamReader(File.OpenRead(markerFile.ItemSpec)))
                {
                    using (var jsonReader = new JsonTextReader(streamReader))
                    {
                        JsonSerializer jsonSerializer = new JsonSerializer();
                        var signTypeItem = jsonSerializer.Deserialize<SignTypeItem>(jsonReader);

                        // the ItemSpec should be the name of the file to sign.  by convention the marker
                        // file is the full path to the file plus a marker extension, so strip the extension.
                        var itemSpec = markerFile.ItemSpec.Substring(0, markerFile.ItemSpec.LastIndexOf('.'));
                        signTypeItems.Add(new Tuple<string, SignTypeItem>(itemSpec, signTypeItem));
                    }
                }
            }

            SigningMetadata = new ITaskItem[signTypeItems.Count];
            for (int i = 0; i < signTypeItems.Count; ++i)
            {
                var taskItem = new TaskItem(signTypeItems[i].Item1);

                if (!string.IsNullOrEmpty(signTypeItems[i].Item2.Authenticode))
                    taskItem.SetMetadata("Authenticode", signTypeItems[i].Item2.Authenticode);
                if (!string.IsNullOrEmpty(signTypeItems[i].Item2.StrongName))
                    taskItem.SetMetadata("StrongName", signTypeItems[i].Item2.StrongName);

                SigningMetadata[i] = taskItem;
            }

            return true;
        }
Beispiel #31
0
        public void SingleAliasUnicodeOnAReference()
        {
            Csc t = new Csc();

            TaskItem reference = new TaskItem("System.Xml.dll");
            reference.SetMetadata("Aliases", "?");

            t.References = new TaskItem[] { reference };
            CommandLine.ValidateHasParameter(t, "/reference:?=System.Xml.dll");
        }
Beispiel #32
0
        /// <summary>
        /// Parse the Parameter element
        /// </summary>
        /// <param name="element"></param>
        private void ReadParameterElement(Xml.XmlElement element)
        {
            Debug.Assert(element != null);
            if (string.Compare(element.Name, "parameter", System.StringComparison.OrdinalIgnoreCase) == 0)
            {
                Xml.XmlAttribute nameAttribute = element.Attributes.GetNamedItem("name") as Xml.XmlAttribute;
                if (nameAttribute != null)
                {
                    Utilities.TaskItem taskItem = new Microsoft.Build.Utilities.TaskItem(nameAttribute.Value);
                    foreach (Xml.XmlNode attribute in element.Attributes)
                    {
                        string attributeName = attribute.Name.ToLower(System.Globalization.CultureInfo.InvariantCulture);
                        if (string.CompareOrdinal(attributeName, "xmlns") == 0 ||
                            attribute.Name.StartsWith("xmlns:", System.StringComparison.Ordinal) ||
                            string.CompareOrdinal(attributeName, "name") == 0
                            )
                        {
                            continue;
                        }
                        string value = DisableEscapeMSBuildVariable ? attribute.Value : Utility.EscapeTextForMSBuildVariable(attribute.Value);
                        taskItem.SetMetadata(attribute.Name, value);
                    }
                    // work around the MSDeploy.exe limition of the Parameter must have the ParameterEntry.
                    // m_parametersList.Add(taskItem);
                    bool fAddNoParameterEntryParameter = true;

                    foreach (Xml.XmlNode childNode in element.ChildNodes)
                    {
                        Xml.XmlElement childElement = childNode as Xml.XmlElement;
                        if (childElement != null)
                        {
                            Utilities.TaskItem childEntry = ReadParameterEntryElement(childElement, taskItem);
                            if (childEntry != null)
                            {
                                fAddNoParameterEntryParameter = false; // we have Parameter entry, supress adding the Parameter with no entry
                                m_parametersList.Add(childEntry);
                            }
                        }
                    }

                    if (fAddNoParameterEntryParameter)
                    {
                        // finally add a parameter without any entry
                        m_parametersList.Add(taskItem);
                    }
                }
            }
        }