public PackageItem(ITaskItem item)
        {
            OriginalItem  = item;
            SourcePath    = item.GetMetadata("FullPath");
            SourceProject = GetMetadata("MSBuildSourceProjectFile");
            string value = GetMetadata("TargetFramework");

            if (!String.IsNullOrWhiteSpace(value))
            {
                TargetFramework = NuGetFramework.Parse(value);
            }
            TargetPath           = item.GetMetadata(nameof(TargetPath));
            AdditionalProperties = GetMetadata(nameof(AdditionalProperties));
            UndefineProperties   = GetMetadata(nameof(UndefineProperties));
            HarvestedFrom        = GetMetadata(nameof(HarvestedFrom));
            Package        = GetMetadata("PackageId");
            PackageVersion = GetMetadata("PackageVersion");
            IsDll          = Path.GetExtension(SourcePath).Equals(".dll", StringComparison.OrdinalIgnoreCase);
            IsPlaceholder  = NuGetAssetResolver.IsPlaceholder(SourcePath);
            IsRef          = TargetPath.StartsWith("ref/", StringComparison.OrdinalIgnoreCase);

            // determine if we need to append filename to TargetPath
            // see https://docs.nuget.org/create/nuspec-reference#specifying-files-to-include-in-the-package
            // SourcePath specifies file and target specifies file - do nothing
            // SourcePath specifies file and Target specifies directory - copy filename
            // SourcePath specifies wildcard files - copy wildcard
            // SourcePath specifies recursive wildcard - do not allow, recursive directory may impact asset selection
            //   we don't want to attempt to expand the wildcard since the build may not yet be complete.

            if (SourcePath.Contains("**"))
            {
                throw new ArgumentException($"Recursive wildcards \"**\" are not permitted in source paths for packages: {SourcePath}.  Recursive directory may impact asset selection and we don't want to attempt to expand the wildcard since the build may not yet be complete.");
            }

            string sourceFile = Path.GetFileName(SourcePath);

            if (!Path.GetExtension(TargetPath).Equals(Path.GetExtension(sourceFile), StringComparison.OrdinalIgnoreCase) ||
                sourceFile.Contains("*"))
            {
                TargetPath = Path.Combine(TargetPath, sourceFile);
            }

            // standardize to /
            TargetPath = TargetPath.Replace('\\', '/');

            int dirLength = TargetPath.LastIndexOf('/');

            TargetDirectory = (dirLength > 0) ? TargetPath.Substring(0, dirLength) : String.Empty;
        }
        protected virtual void CreateProjectReferences(ModuleDefinition module)
        {
            ICollection <AssemblyNameReference> dependingOnAssemblies = GetAssembliesDependingOn(module);

            this.projectFileManager.CreateReferencesProjectItem(dependingOnAssemblies.Count);

            string assemblyName = module.IsMain ? module.Assembly.Name.Name : Utilities.GetNetmoduleName(module);
            string copiedReferencesSubfolder = assemblyName + "References";
            string referencesPath            = TargetPath.Remove(TargetPath.LastIndexOf(Path.DirectorySeparatorChar)) + Path.DirectorySeparatorChar + copiedReferencesSubfolder;

            ICollection <AssemblyNameReference> filteredDependingOnAssemblies = FilterDependingOnAssemblies(dependingOnAssemblies);
            int assemblyReferenceIndex  = 0;
            SpecialTypeAssembly special = module.IsReferenceAssembly() ? SpecialTypeAssembly.Reference : SpecialTypeAssembly.None;

            foreach (AssemblyNameReference reference in filteredDependingOnAssemblies)
            {
                this.CreateProjectReferenceInternal(module, reference, ref assemblyReferenceIndex, special, referencesPath, copiedReferencesSubfolder);

                assemblyReferenceIndex++;
            }
        }
Пример #3
0
        private void OnTargetEndPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (context != null && SynchronizationContext.Current != context)
            {
                context.Post((o) =>
                {
                    SynchronizationContext.SetSynchronizationContext(context);
                    OnTargetEndPropertyChanged(sender, e);
                }, this);
                return;
            }

            if (Mode == BindingMode.OneWayToTarget)
            {
                return;
            }

            var targetToken = TargetPath.Substring(TargetPath.LastIndexOf('.') + 1);

            if (e.PropertyName != targetToken)
            {
                return;
            }

            var sourceObject = sourceObjects.Last();
            var sourceType   = sourceObject.GetType();
            var sourceInfo   = sourceInfos.Last();
            var targetObject = targetObjects.Last().Target;

            if (targetObject == null)
            {
                Deactivate();
                return;
            }

            object value = null;

            if (targetObject.GetType().IsArray)
            {
                value = ((Array)targetObject).GetValue(targetIndices.Last().Cast <int>().ToArray());
            }
            else
            {
                value = targetInfos.Last().GetValue(targetObject, targetIndices.Last());
            }

            if (ValueConverter != null)
            {
                value = ValueConverter.ConvertBack(value, sourceInfo.PropertyType, ValueConverterParameter);
            }
            else
            {
                value = GetConvertedValue(value, sourceType.IsArray ? sourceType.GetElementType() : sourceInfo.PropertyType);
            }


            if (sourceType.IsArray)
            {
                ((Array)sourceObject).SetValue(value, sourceIndices.Last().Cast <int>().ToArray());
            }
            else
            {
                sourceInfo.SetValue(sourceObject, value, sourceIndices.Last());
            }
        }