Beispiel #1
0
 private string Preprocess(string text, IDictionary <string, string> parameters)
 {
     using (var input = new MemoryStream(Encoding.UTF8.GetBytes(text)))
     {
         using (var output = new MemoryStream())
         {
             PPFilePreprocessor.Preprocess(input, output, parameters);
             return(Encoding.UTF8.GetString(output.ToArray()));
         }
     }
 }
Beispiel #2
0
        private LibraryExport ExportPackage(PackageDescription package)
        {
            var builder = LibraryExportBuilder.Create(package);

            builder.WithNativeLibraries(PopulateAssets(package, package.NativeLibraries));
            builder.WithRuntimeAssemblies(PopulateAssets(package, package.RuntimeAssemblies));
            builder.WithCompilationAssemblies(PopulateAssets(package, package.CompileTimeAssemblies));
            builder.WithSourceReferences(GetSharedSources(package));
            builder.WithAnalyzerReference(GetAnalyzerReferences(package));

            if (package.ContentFiles.Any())
            {
                var parameters = PPFileParameters.CreateForProject(_rootProject.Project);
                Action <Stream, Stream> transform = (input, output) => PPFilePreprocessor.Preprocess(input, output, parameters);

                var sourceCodeLanguage = _rootProject.Project.GetSourceCodeLanguage();
                var languageGroups     = package.ContentFiles.GroupBy(file => file.CodeLanguage);
                var selectedGroup      = languageGroups.FirstOrDefault(g => g.Key == sourceCodeLanguage) ??
                                         languageGroups.FirstOrDefault(g => g.Key == null);
                if (selectedGroup != null)
                {
                    foreach (var contentFile in selectedGroup)
                    {
                        if (contentFile.CodeLanguage != null &&
                            string.Compare(contentFile.CodeLanguage, sourceCodeLanguage, StringComparison.OrdinalIgnoreCase) != 0)
                        {
                            continue;
                        }

                        var fileTransform = contentFile.PPOutputPath != null ? transform : null;

                        var fullPath = Path.Combine(package.Path, contentFile.Path);
                        if (contentFile.BuildAction == BuildAction.Compile)
                        {
                            builder.AddSourceReference(LibraryAsset.CreateFromRelativePath(package.Path, contentFile.Path, fileTransform));
                        }
                        else if (contentFile.BuildAction == BuildAction.EmbeddedResource)
                        {
                            builder.AddEmbedddedResource(LibraryAsset.CreateFromRelativePath(package.Path, contentFile.Path, fileTransform));
                        }
                        if (contentFile.CopyToOutput)
                        {
                            builder.AddRuntimeAsset(new LibraryAsset(contentFile.Path, contentFile.OutputPath, fullPath, fileTransform));
                        }
                    }
                }
            }

            return(builder.Build());
        }
Beispiel #3
0
        private LibraryExport ExportPackage(TargetLibraryWithAssets library)
        {
            var builder = LibraryExportBuilder.Create(library);

            builder.AddNativeLibraryGroup(new LibraryAssetGroup(PopulateAssets(library, library.NativeLibraries)));
            builder.AddRuntimeAssemblyGroup(new LibraryAssetGroup(PopulateAssets(library, library.RuntimeAssemblies)));
            builder.WithResourceAssemblies(PopulateResources(library, library.ResourceAssemblies));
            builder.WithCompilationAssemblies(PopulateAssets(library, library.CompileTimeAssemblies));

            if (library.Identity.Type.Equals(LibraryType.Package))
            {
                builder.WithSourceReferences(GetSharedSources((PackageDescription)library));
                builder.WithAnalyzerReference(GetAnalyzerReferences((PackageDescription)library));
            }

            if (library.ContentFiles.Any())
            {
                var parameters = PPFileParameters.CreateForProject(_rootProject.Project);
                Action <Stream, Stream> transform = (input, output) => PPFilePreprocessor.Preprocess(input, output, parameters);

                var sourceCodeLanguage = _rootProject.Project.GetSourceCodeLanguage();
                var languageGroups     = library.ContentFiles.GroupBy(file => file.CodeLanguage);
                var selectedGroup      = languageGroups.FirstOrDefault(g => g.Key == sourceCodeLanguage) ??
                                         languageGroups.FirstOrDefault(g => g.Key == null);
                if (selectedGroup != null)
                {
                    foreach (var contentFile in selectedGroup)
                    {
                        if (contentFile.CodeLanguage != null &&
                            string.Compare(contentFile.CodeLanguage, sourceCodeLanguage, StringComparison.OrdinalIgnoreCase) != 0)
                        {
                            continue;
                        }

                        var fileTransform = contentFile.PPOutputPath != null ? transform : null;

                        var fullPath = Path.Combine(library.Path, contentFile.Path);
                        if (contentFile.BuildAction == BuildAction.Compile)
                        {
                            builder.AddSourceReference(LibraryAsset.CreateFromRelativePath(library.Path, contentFile.Path, fileTransform));
                        }
                        else if (contentFile.BuildAction == BuildAction.EmbeddedResource)
                        {
                            builder.AddEmbedddedResource(LibraryAsset.CreateFromRelativePath(library.Path, contentFile.Path, fileTransform));
                        }
                        if (contentFile.CopyToOutput)
                        {
                            builder.AddRuntimeAsset(new LibraryAsset(contentFile.Path, contentFile.OutputPath, fullPath, fileTransform));
                        }
                    }
                }
            }
            if (library.RuntimeTargets.Any())
            {
                foreach (var targetGroup in library.RuntimeTargets.GroupBy(t => t.Runtime))
                {
                    var runtime = new List <LibraryAsset>();
                    var native  = new List <LibraryAsset>();

                    foreach (var lockFileRuntimeTarget in targetGroup)
                    {
                        if (string.Equals(lockFileRuntimeTarget.AssetType, "native", StringComparison.OrdinalIgnoreCase))
                        {
                            native.Add(LibraryAsset.CreateFromRelativePath(library.Path, lockFileRuntimeTarget.Path));
                        }
                        else if (string.Equals(lockFileRuntimeTarget.AssetType, "runtime", StringComparison.OrdinalIgnoreCase))
                        {
                            runtime.Add(LibraryAsset.CreateFromRelativePath(library.Path, lockFileRuntimeTarget.Path));
                        }
                    }

                    if (runtime.Any())
                    {
                        builder.AddRuntimeAssemblyGroup(new LibraryAssetGroup(targetGroup.Key, runtime.Where(a => !PackageDependencyProvider.IsPlaceholderFile(a.RelativePath))));
                    }

                    if (native.Any())
                    {
                        builder.AddNativeLibraryGroup(new LibraryAssetGroup(targetGroup.Key, native.Where(a => !PackageDependencyProvider.IsPlaceholderFile(a.RelativePath))));
                    }
                }
            }

            return(builder.Build());
        }