示例#1
0
        internal T4PsiModule([NotNull] Lifetime lifetime, [NotNull] IPsiModules psiModules, [NotNull] DocumentManager documentManager,
                             [NotNull] ChangeManager changeManager, [NotNull] IAssemblyFactory assemblyFactory, [NotNull] IShellLocks shellLocks,
                             [NotNull] IProjectFile projectFile, [NotNull] T4FileDataCache fileDataCache, [NotNull] T4Environment t4Environment,
                             [NotNull] OutputAssemblies outputAssemblies)
        {
            _lifetime = lifetime;
            lifetime.AddAction(Dispose);

            _psiModules      = psiModules;
            _assemblyFactory = assemblyFactory;
            _changeManager   = changeManager;
            _shellLocks      = shellLocks;

            _projectFile = projectFile;
            IProject project = projectFile.GetProject();

            Assertion.AssertNotNull(project, "project != null");
            _project  = project;
            _solution = project.GetSolution();

            changeManager.RegisterChangeProvider(lifetime, this);
            changeManager.AddDependency(lifetime, psiModules, this);

            _t4Environment    = t4Environment;
            _outputAssemblies = outputAssemblies;
            _resolveProject   = new T4ResolveProject(lifetime, _solution, _shellLocks, t4Environment.PlatformID, project);

            _sourceFile = CreateSourceFile(projectFile, documentManager);

            _isValid = true;
            fileDataCache.FileDataChanged.Advise(lifetime, OnDataFileChanged);
            AddBaseReferences();
        }
        public override bool RunTask()
        {
            var output = new Dictionary <Guid, ITaskItem> ();

            foreach (var assembly in InputAssemblies)
            {
                using (var pe = new PEReader(File.OpenRead(assembly.ItemSpec))) {
                    var reader = pe.GetMetadataReader();
                    var module = reader.GetModuleDefinition();
                    var mvid   = reader.GetGuid(module.Mvid);
                    if (!output.ContainsKey(mvid))
                    {
                        output.Add(mvid, assembly);

                        // Set metadata, such as %(FrameworkAssembly) and %(HasMonoAndroidReference)
                        string packageId         = assembly.GetMetadata("NuGetPackageId");
                        bool   frameworkAssembly = packageId.StartsWith("Microsoft.NETCore.App.Runtime.") ||
                                                   packageId.StartsWith("Microsoft.Android.Runtime.");
                        assembly.SetMetadata("FrameworkAssembly", frameworkAssembly.ToString());
                        assembly.SetMetadata("HasMonoAndroidReference", MonoAndroidHelper.HasMonoAndroidReference(reader).ToString());
                    }
                    else
                    {
                        Log.LogDebugMessage($"Removing duplicate: {assembly.ItemSpec}");
                    }
                }
            }

            OutputAssemblies = output.Values.ToArray();

            // Set %(AbiDirectory) for architecture-specific assemblies
            var fileNames = new Dictionary <string, ITaskItem> (StringComparer.OrdinalIgnoreCase);

            foreach (var assembly in OutputAssemblies)
            {
                var fileName = Path.GetFileName(assembly.ItemSpec);
                if (fileNames.TryGetValue(fileName, out ITaskItem other))
                {
                    SetAbiDirectory(assembly, fileName);
                    SetAbiDirectory(other, fileName);
                }
                else
                {
                    fileNames.Add(fileName, assembly);
                    assembly.SetMetadata("IntermediateLinkerOutput", Path.Combine(IntermediateAssemblyDirectory, fileName));
                }
            }

            // Set ShrunkAssemblies for _RemoveRegisterAttribute and <BuildApk/>
            if (!string.IsNullOrEmpty(LinkMode) && !string.Equals(LinkMode, "None", StringComparison.OrdinalIgnoreCase))
            {
                ShrunkAssemblies = OutputAssemblies.Select(a => {
                    var dir  = Path.GetDirectoryName(a.ItemSpec);
                    var file = Path.GetFileName(a.ItemSpec);
                    return(new TaskItem(a)
                    {
                        ItemSpec = Path.Combine(dir, "shrunk", file),
                    });
                }).ToArray();
            }

            return(!Log.HasLoggedErrors);
        }
示例#3
0
        public override bool RunTask()
        {
            var output  = new Dictionary <Guid, ITaskItem> ();
            var symbols = new Dictionary <string, ITaskItem> ();

            if (ResolvedSymbols != null)
            {
                foreach (var symbol in ResolvedSymbols)
                {
                    symbols [symbol.ItemSpec] = symbol;
                }
            }

            foreach (var assembly in InputAssemblies)
            {
                if (!File.Exists(assembly.ItemSpec))
                {
                    Log.LogDebugMessage($"Skipping non-existent dependency '{assembly.ItemSpec}'.");
                    continue;
                }
                using (var pe = new PEReader(File.OpenRead(assembly.ItemSpec))) {
                    var reader = pe.GetMetadataReader();
                    var module = reader.GetModuleDefinition();
                    var mvid   = reader.GetGuid(module.Mvid);
                    if (!output.ContainsKey(mvid))
                    {
                        output.Add(mvid, assembly);

                        // Set metadata, such as %(FrameworkAssembly) and %(HasMonoAndroidReference)
                        string packageId         = assembly.GetMetadata("NuGetPackageId");
                        bool   frameworkAssembly = packageId.StartsWith("Microsoft.NETCore.App.Runtime.") ||
                                                   packageId.StartsWith("Microsoft.Android.Runtime.");
                        assembly.SetMetadata("FrameworkAssembly", frameworkAssembly.ToString());
                        assembly.SetMetadata("HasMonoAndroidReference", MonoAndroidHelper.HasMonoAndroidReference(reader).ToString());
                    }
                    else
                    {
                        Log.LogDebugMessage($"Removing duplicate: {assembly.ItemSpec}");

                        var symbolPath = Path.ChangeExtension(assembly.ItemSpec, ".pdb");
                        if (symbols.Remove(symbolPath))
                        {
                            Log.LogDebugMessage($"Removing duplicate: {symbolPath}");
                        }
                    }
                }
            }

            OutputAssemblies = output.Values.ToArray();
            ResolvedSymbols  = symbols.Values.ToArray();

            // Set %(DestinationSubDirectory) and %(DestinationSubPath) for architecture-specific assemblies
            var fileNames = new Dictionary <string, ITaskItem> (StringComparer.OrdinalIgnoreCase);

            foreach (var assembly in OutputAssemblies)
            {
                var fileName = Path.GetFileName(assembly.ItemSpec);
                symbols.TryGetValue(Path.ChangeExtension(assembly.ItemSpec, ".pdb"), out var symbol);
                if (fileNames.TryGetValue(fileName, out ITaskItem other))
                {
                    SetDestinationSubDirectory(assembly, fileName, symbol);
                    if (other != null)
                    {
                        symbols.TryGetValue(Path.ChangeExtension(other.ItemSpec, ".pdb"), out symbol);
                        SetDestinationSubDirectory(other, fileName, symbol);
                        // We don't need to check "other" again
                        fileNames [fileName] = null;
                    }
                }
                else
                {
                    fileNames.Add(fileName, assembly);
                    assembly.SetDestinationSubPath();
                    symbol?.SetDestinationSubPath();
                }
            }

            // Set ShrunkAssemblies for _RemoveRegisterAttribute and <BuildApk/>
            if (!string.IsNullOrEmpty(LinkMode) && !string.Equals(LinkMode, "None", StringComparison.OrdinalIgnoreCase) && !UseSharedRuntime)
            {
                ShrunkAssemblies = OutputAssemblies.Select(a => {
                    var dir  = Path.GetDirectoryName(a.ItemSpec);
                    var file = Path.GetFileName(a.ItemSpec);
                    return(new TaskItem(a)
                    {
                        ItemSpec = Path.Combine(dir, "shrunk", file),
                    });
                }).ToArray();
            }

            return(!Log.HasLoggedErrors);
        }
        public override bool RunTask()
        {
            var output  = new List <ITaskItem> ();
            var symbols = new Dictionary <string, ITaskItem> ();

            if (ResolvedSymbols != null)
            {
                foreach (var symbol in ResolvedSymbols)
                {
                    symbols [symbol.ItemSpec] = symbol;
                }
            }

            // Group by assembly file name
            foreach (var group in InputAssemblies.Where(Filter).GroupBy(a => Path.GetFileName(a.ItemSpec)))
            {
                // Get the unique list of MVIDs
                var  mvids = new HashSet <Guid> ();
                bool?frameworkAssembly = null, hasMonoAndroidReference = null;
                foreach (var assembly in group)
                {
                    using (var pe = new PEReader(File.OpenRead(assembly.ItemSpec))) {
                        var reader = pe.GetMetadataReader();
                        var module = reader.GetModuleDefinition();
                        var mvid   = reader.GetGuid(module.Mvid);
                        mvids.Add(mvid);

                        // Calculate %(FrameworkAssembly) and %(HasMonoAndroidReference) for the first
                        if (frameworkAssembly == null)
                        {
                            string packageId = assembly.GetMetadata("NuGetPackageId") ?? "";
                            frameworkAssembly = packageId.StartsWith("Microsoft.NETCore.App.Runtime.") ||
                                                packageId.StartsWith("Microsoft.Android.Runtime.");
                        }
                        if (hasMonoAndroidReference == null)
                        {
                            hasMonoAndroidReference = MonoAndroidHelper.HasMonoAndroidReference(reader);
                        }
                        assembly.SetMetadata("FrameworkAssembly", frameworkAssembly.ToString());
                        assembly.SetMetadata("HasMonoAndroidReference", hasMonoAndroidReference.ToString());
                    }
                }
                // If we end up with more than 1 unique mvid, we need *all* assemblies
                if (mvids.Count > 1)
                {
                    foreach (var assembly in group)
                    {
                        symbols.TryGetValue(Path.ChangeExtension(assembly.ItemSpec, ".pdb"), out var symbol);
                        SetDestinationSubDirectory(assembly, group.Key, symbol);
                        output.Add(assembly);
                    }
                }
                else
                {
                    // Otherwise only include the first assembly
                    bool first = true;
                    foreach (var assembly in group)
                    {
                        var symbolPath = Path.ChangeExtension(assembly.ItemSpec, ".pdb");
                        if (first)
                        {
                            first = false;
                            if (symbols.TryGetValue(symbolPath, out var symbol))
                            {
                                symbol.SetDestinationSubPath();
                            }
                            assembly.SetDestinationSubPath();
                            output.Add(assembly);
                        }
                        else
                        {
                            symbols.Remove(symbolPath);
                        }
                    }
                }
            }

            OutputAssemblies = output.ToArray();
            ResolvedSymbols  = symbols.Values.ToArray();

            // Set ShrunkAssemblies for _RemoveRegisterAttribute and <BuildApk/>
            if (PublishTrimmed)
            {
                ShrunkAssemblies = OutputAssemblies.Select(a => {
                    var dir  = Path.GetDirectoryName(a.ItemSpec);
                    var file = Path.GetFileName(a.ItemSpec);
                    return(new TaskItem(a)
                    {
                        ItemSpec = Path.Combine(dir, "shrunk", file),
                    });
                }).ToArray();
            }

            return(!Log.HasLoggedErrors);
        }
示例#5
0
        internal T4PsiModule([NotNull] Lifetime lifetime, [NotNull] IPsiModules psiModules, [NotNull] DocumentManager documentManager,
            [NotNull] ChangeManager changeManager, [NotNull] IAssemblyFactory assemblyFactory, [NotNull] IShellLocks shellLocks,
            [NotNull] IProjectFile projectFile, [NotNull] T4FileDataCache fileDataCache, [NotNull] T4Environment t4Environment,
            [NotNull] OutputAssemblies outputAssemblies)
        {
            _lifetime = lifetime;
            lifetime.AddAction(Dispose);

            _psiModules = psiModules;
            _assemblyFactory = assemblyFactory;
            _changeManager = changeManager;
            _shellLocks = shellLocks;

            _projectFile = projectFile;
            IProject project = projectFile.GetProject();
            Assertion.AssertNotNull(project, "project != null");
            _project = project;
            _solution = project.GetSolution();

            changeManager.RegisterChangeProvider(lifetime, this);
            changeManager.AddDependency(lifetime, psiModules, this);

            _t4Environment = t4Environment;
            _outputAssemblies = outputAssemblies;
            _resolveProject = new T4ResolveProject(lifetime, _solution, _shellLocks, t4Environment.PlatformID, project);

            _sourceFile = CreateSourceFile(projectFile, documentManager);

            _isValid = true;
            fileDataCache.FileDataChanged.Advise(lifetime, OnDataFileChanged);
            AddBaseReferences();
        }
 public T4ProjectReferenceResolver([NotNull] IPsiModules psiModules, [NotNull] OutputAssemblies outputAssemblies)
 {
     PsiModules       = psiModules;
     OutputAssemblies = outputAssemblies;
 }