public static CompilationOptions ConvertFrom(ITaskItem compilerOptionsItem)
        {
            if (compilerOptionsItem == null)
            {
                return(null);
            }

            return(new CompilationOptions(
                       compilerOptionsItem.GetMetadata("DefineConstants")?.Split(';'),
                       compilerOptionsItem.GetMetadata("LangVersion"),
                       compilerOptionsItem.GetMetadata("PlatformTarget"),
                       compilerOptionsItem.GetBooleanMetadata("AllowUnsafeBlocks"),
                       compilerOptionsItem.GetBooleanMetadata("WarningsAsErrors"),
                       compilerOptionsItem.GetBooleanMetadata("Optimize"),
                       compilerOptionsItem.GetMetadata("AssemblyOriginatorKeyFile"),
                       compilerOptionsItem.GetBooleanMetadata("DelaySign"),
                       compilerOptionsItem.GetBooleanMetadata("PublicSign"),
                       compilerOptionsItem.GetMetadata("DebugType"),
                       "exe".Equals(compilerOptionsItem.GetMetadata("OutputType"), StringComparison.OrdinalIgnoreCase),
                       compilerOptionsItem.GetBooleanMetadata("GenerateDocumentationFile")));
        }
Beispiel #2
0
        private void ProduceContentAsset(ITaskItem contentFile)
        {
            string resolvedPath;

            if (!_resolvedPaths.TryGetValue(contentFile.ItemSpec, out resolvedPath))
            {
                Log.LogWarning(Strings.UnableToFindResolvedPath, contentFile.ItemSpec);
                return;
            }

            string pathToFinalAsset = resolvedPath;
            string ppOutputPath     = contentFile.GetMetadata("ppOutputPath");
            string parentPackage    = contentFile.GetMetadata(MetadataKeys.ParentPackage);

            if (ppOutputPath != null)
            {
                if (string.IsNullOrEmpty(ContentPreprocessorOutputDirectory))
                {
                    throw new BuildErrorException(Strings.ContentPreproccessorParameterRequired, nameof(ProduceContentAssets), nameof(ContentPreprocessorOutputDirectory));
                }
                string [] parts = parentPackage?.Split('/');
                if (parts == null)
                {
                    throw new BuildErrorException(Strings.ContentFileDoesNotContainExpectedParentPackageInformation, contentFile.ItemSpec);
                }

                // We need the preprocessed output, so let's run the preprocessor here
                string relativeOutputPath = Path.Combine(parts[0], parts[1], ppOutputPath);
                if (AssetPreprocessor.Process(resolvedPath, relativeOutputPath, out pathToFinalAsset))
                {
                    _fileWrites.Add(new TaskItem(pathToFinalAsset));
                }
            }

            if (contentFile.GetBooleanMetadata("copyToOutput") == true)
            {
                string outputPath = contentFile.GetMetadata("outputPath") ?? ppOutputPath;

                if (outputPath != null)
                {
                    var item = new TaskItem(pathToFinalAsset);
                    item.SetMetadata("TargetPath", outputPath);
                    item.SetMetadata(MetadataKeys.ParentPackage, parentPackage);

                    _copyLocalItems.Add(item);
                }
                else
                {
                    Log.LogWarning(Strings.ContentItemDoesNotProvideOutputPath, pathToFinalAsset, "copyToOutput", "outputPath", "ppOutputPath");
                }
            }

            // TODO if build action is none do we even need to write the processed file above?
            string buildAction = contentFile.GetMetadata("buildAction");

            if (!string.Equals(buildAction, "none", StringComparison.OrdinalIgnoreCase))
            {
                var item = new TaskItem(pathToFinalAsset);
                item.SetMetadata(MetadataKeys.ParentPackage, parentPackage);

                // We'll put additional metadata on the item so we can convert it back to the real item group in our targets
                item.SetMetadata("ProcessedItemType", buildAction);

                // TODO is this needed for .NETCore?
                // If this is XAML, the build targets expect Link metadata to construct the relative path
                if (string.Equals(buildAction, "Page", StringComparison.OrdinalIgnoreCase))
                {
                    item.SetMetadata("Link", Path.Combine("NuGet", parentPackage, Path.GetFileName(resolvedPath)));
                }

                _contentItems.Add(item);
            }
        }
        private void ProduceContentAsset(ITaskItem contentFile)
        {
            string resolvedPath     = contentFile.ItemSpec;
            string pathToFinalAsset = resolvedPath;
            string ppOutputPath     = contentFile.GetMetadata(MetadataKeys.PPOutputPath);
            string packageName      = contentFile.GetMetadata(MetadataKeys.NuGetPackageId);
            string packageVersion   = contentFile.GetMetadata(MetadataKeys.NuGetPackageVersion);

            if (!string.IsNullOrEmpty(ppOutputPath))
            {
                if (string.IsNullOrEmpty(ContentPreprocessorOutputDirectory))
                {
                    throw new BuildErrorException(Strings.ContentPreproccessorParameterRequired, nameof(ProduceContentAssets), nameof(ContentPreprocessorOutputDirectory));
                }

                // We need the preprocessed output, so let's run the preprocessor here
                string relativeOutputPath = Path.Combine(packageName, packageVersion, ppOutputPath);
                if (AssetPreprocessor.Process(resolvedPath, relativeOutputPath, out pathToFinalAsset))
                {
                    _fileWrites.Add(new TaskItem(pathToFinalAsset));
                }
            }

            if (contentFile.GetBooleanMetadata(MetadataKeys.CopyToOutput) == true)
            {
                string outputPath = contentFile.GetMetadata(MetadataKeys.OutputPath);
                outputPath = string.IsNullOrEmpty(outputPath) ? ppOutputPath : outputPath;

                if (!string.IsNullOrEmpty(outputPath))
                {
                    var item = new TaskItem(pathToFinalAsset);
                    item.SetMetadata("TargetPath", outputPath);
                    item.SetMetadata(MetadataKeys.NuGetPackageId, packageName);
                    item.SetMetadata(MetadataKeys.NuGetPackageVersion, packageVersion);

                    _copyLocalItems.Add(item);
                }
                else
                {
                    Log.LogWarning(Strings.ContentItemDoesNotProvideOutputPath, pathToFinalAsset, MetadataKeys.CopyToOutput, MetadataKeys.OutputPath, MetadataKeys.PPOutputPath);
                }
            }

            // TODO if build action is none do we even need to write the processed file above?
            string buildAction = contentFile.GetMetadata(MetadataKeys.BuildAction);

            if (!string.Equals(buildAction, "none", StringComparison.OrdinalIgnoreCase))
            {
                var item = new TaskItem(pathToFinalAsset);
                item.SetMetadata(MetadataKeys.NuGetPackageId, packageName);
                item.SetMetadata(MetadataKeys.NuGetPackageVersion, packageVersion);

                // We'll put additional metadata on the item so we can convert it back to the real item group in our targets
                item.SetMetadata("ProcessedItemType", buildAction);

                // TODO is this needed for .NETCore?
                // If this is XAML, the build targets expect Link metadata to construct the relative path
                if (string.Equals(buildAction, "Page", StringComparison.OrdinalIgnoreCase))
                {
                    item.SetMetadata("Link", Path.Combine("NuGet", packageName, packageVersion, Path.GetFileName(resolvedPath)));
                }

                _contentItems.Add(item);
            }
        }