示例#1
0
文件: Program.cs 项目: dsyme/cli
        private static bool AddNonCultureResources(Project project, List<string> compilerArgs, string intermediateOutputPath)
        {
            var resgenFiles = CompilerUtil.GetNonCultureResources(project, intermediateOutputPath);

            foreach (var resgenFile in resgenFiles)
            {
                if (ResourceUtility.IsResxFile(resgenFile.InputFile))
                {
                    var result =
                        Command.Create("dotnet-resgen",
                            $"\"{resgenFile.InputFile}\" -o \"{resgenFile.OutputFile}\" -v \"{project.Version.Version}\"")
                            .ForwardStdErr()
                            .ForwardStdOut()
                            .Execute();

                    if (result.ExitCode != 0)
                    {
                        return false;
                    }

                    compilerArgs.Add($"--resource:\"{resgenFile.OutputFile}\",{Path.GetFileName(resgenFile.MetadataName)}");
                }
                else
                {
                    compilerArgs.Add($"--resource:\"{resgenFile.InputFile}\",{Path.GetFileName(resgenFile.MetadataName)}");
                }
            }

            return true;
        }
示例#2
0
 public ArtifactPathsCalculator(Project project, string compiledArtifactsPath, string packageArtifactsPath, string configuration)
 {
     _project = project;
     CompiledArtifactsPathParameter = compiledArtifactsPath;
     PackageArtifactsPathParameter = packageArtifactsPath;
     _configuration = configuration;
 }
示例#3
0
        private static Func<string, string> GetScriptVariable(Project project, Func<string, string> getVariable)
        {
            var keys = new Dictionary<string, Func<string>>(StringComparer.OrdinalIgnoreCase)
            {
                { "project:Directory", () => project.ProjectDirectory },
                { "project:Name", () => project.Name },
                { "project:Version", () => project.Version.ToString() },
            };

            return key =>
            {
                // try returning key from dictionary
                Func<string> valueFactory;
                if (keys.TryGetValue(key, out valueFactory))
                {
                    return valueFactory();
                }

                // try returning command-specific key
                var value = getVariable(key);
                if (!string.IsNullOrEmpty(value))
                {
                    return value;
                }

                // try returning environment variable
                return Environment.GetEnvironmentVariable(key);
            };
        }
示例#4
0
 private static CommandSpec ResolveFromProjectPath(string commandName, IEnumerable<string> args, Project project, string[] inferredExtensionList)
 {
     var commandPath = Env.GetCommandPathFromRootPath(project.ProjectDirectory, commandName, inferredExtensionList);
     return commandPath == null
         ? null
         : CreateCommandSpecPreferringExe(commandName, args, commandPath, CommandResolutionStrategy.ProjectLocal);
 }
示例#5
0
        public BuildCommand(
            string projectPath,
            string output="",
            string tempOutput="",
            string configuration="",
            bool noHost=false,
            bool native=false,
            string architecture="",
            string ilcArgs="",
            string ilcPath="",
            string appDepSDKPath="",
            bool nativeCppMode=false,
            string cppCompilerFlags="",
            bool buildProfile=true,
            bool forceIncrementalUnsafe=false
            )
            : base("dotnet")
        {
            _projectPath = projectPath;
            _project = ProjectReader.GetProject(projectPath);

            _outputDirectory = output;
            _tempOutputDirectory = tempOutput;
            _configuration = configuration;
            _noHost = noHost;
            _native = native;
            _architecture = architecture;
            _ilcArgs = ilcArgs;
            _ilcPath = ilcPath;
            _appDepSDKPath = appDepSDKPath;
            _nativeCppMode = nativeCppMode;
            _cppCompilerFlags = cppCompilerFlags;
            _buildProfile = buildProfile;
            _forceIncrementalUnsafe = forceIncrementalUnsafe;
        }
示例#6
0
 public static CommandSpec TryResolveScriptCommandSpec(string commandName, IEnumerable<string> args, Project project, string[] inferredExtensionList)
 {
     return ResolveFromRootedCommand(commandName, args) ??
            ResolveFromProjectPath(commandName, args, project, inferredExtensionList) ??
            ResolveFromAppBase(commandName, args) ??
            ResolveFromPath(commandName, args);
 }
示例#7
0
文件: Compiler.cs 项目: ibebbs/cli
        protected static bool AddNonCultureResources(Project project, List<string> compilerArgs, string intermediateOutputPath)
        {
            var resgenFiles = CompilerUtil.GetNonCultureResources(project, intermediateOutputPath);

            foreach (var resgenFile in resgenFiles)
            {
                if (ResourceUtility.IsResxFile(resgenFile.InputFile))
                {
                    var arguments = new[]
                    {
                        resgenFile.InputFile,
                        $"-o:{resgenFile.OutputFile}",
                        $"-v:{project.Version.Version}"
                    };

                    var rsp = Path.Combine(intermediateOutputPath, $"dotnet-resgen-resx.rsp");
                    File.WriteAllLines(rsp, arguments);

                    var result = Resgen.ResgenCommand.Run(new[] { $"@{rsp}" });

                    if (result != 0)
                    {
                        return false;
                    }

                    compilerArgs.Add($"--resource:\"{resgenFile.OutputFile},{Path.GetFileName(resgenFile.MetadataName)}\"");
                }
                else
                {
                    compilerArgs.Add($"--resource:\"{resgenFile.InputFile},{Path.GetFileName(resgenFile.MetadataName)}\"");
                }
            }

            return true;
        }
示例#8
0
 public RuntimeOutputFiles(string basePath,
     Project project,
     string configuration,
     NuGetFramework framework,
     string runtimeIdentifier) : base(basePath, project, configuration, framework)
 {
     _runtimeIdentifier = runtimeIdentifier;
 }
示例#9
0
        public ScriptExecutorTests()
        {
            _root = Temp.CreateDirectory();

            var sourceTestProjectPath = Path.Combine(s_testProjectRoot, "TestApp");
            binTestProjectPath = _root.CopyDirectory(sourceTestProjectPath).Path;
            project = ProjectContext.Create(binTestProjectPath, NuGetFramework.Parse("netstandardapp1.5")).ProjectFile;
        }
示例#10
0
        public static List<CultureResgenIO> GetCultureResources(Project project, string outputPath, CommonCompilerOptions compilationOptions)
        {
            if (compilationOptions.EmbedInclude == null)
            {
                return GetCultureResources(project, outputPath);
            }

            return GetCultureResourcesFromIncludeEntries(project, outputPath, compilationOptions);
        }
示例#11
0
 protected override IEnumerable<ProjectContext> BuildProjectContexts(Project project)
 {
     foreach (var framework in project.GetTargetFrameworks())
     {
         yield return CreateBaseProjectBuilder(project)
             .AsDesignTime()
             .WithTargetFramework(framework.FrameworkName)
             .Build();
     }
 }
示例#12
0
 public PublishCommand(string projectPath, string framework="", string runtime="", string output="", string config="")
     : base("dotnet")
 {
     _path = projectPath;
     _project = ProjectReader.GetProject(projectPath);
     _framework = framework;
     _runtime = runtime;
     _output = output;
     _config = config;
 }
示例#13
0
 public BuildProjectCommand(
     Project project,
     string buildBasePath,
     string configuration,
     string versionSuffix)
 {
     _project = project;
     _buildBasePath = buildBasePath;
     _configuration = configuration;
     _versionSuffix = versionSuffix;
 }
示例#14
0
 public BuildProjectCommand(
     Project project,
     string buildBasePath,
     string configuration,
     BuildWorkspace workspace)
 {
     _project = project;
     _buildBasePath = buildBasePath;
     _configuration = configuration;
     _workspace = workspace;
 }
示例#15
0
 public PublishCommand(string projectPath, string framework = "", string runtime = "", string output = "", string config = "", bool forcePortable = false, bool noBuild = false)
     : base("dotnet")
 {
     _path = projectPath;
     _project = ProjectReader.GetProject(projectPath);
     _framework = framework;
     _runtime = runtime;
     _output = output;
     _config = config;
     _noBuild = noBuild;
 }
示例#16
0
 // used in incremental compilation
 public static List<NonCultureResgenIO> GetNonCultureResources(Project project, string intermediateOutputPath)
 {
     return 
         (from resourceFile in project.Files.ResourceFiles
             let inputFile = resourceFile.Key
             where string.IsNullOrEmpty(ResourceUtility.GetResourceCultureName(inputFile))
             let metadataName = GetResourceFileMetadataName(project, resourceFile)
             let outputFile = ResourceUtility.IsResxFile(inputFile) ? Path.Combine(intermediateOutputPath, metadataName) : null
             select new NonCultureResgenIO(inputFile, outputFile, metadataName)
             ).ToList();
 }
示例#17
0
 public BuildProjectCommand(
     Project project, 
     ArtifactPathsCalculator artifactPathsCalculator, 
     string intermediateOutputPath, 
     string configuration)
 {
     _project = project;
     _artifactPathsCalculator = artifactPathsCalculator;
     _intermediateOutputPath = intermediateOutputPath;
     _configuration = configuration;
 }
示例#18
0
 public BuildProjectCommand(
     Project project, 
     ArtifactPathsCalculator artifactPathsCalculator, 
     string buildBasePath, 
     string configuration)
 {
     _project = project;
     _artifactPathsCalculator = artifactPathsCalculator;
     _buildBasePath = buildBasePath;
     _configuration = configuration;
 }
示例#19
0
 // used in incremental compilation
 public static List<CultureResgenIO> GetCultureResources(Project project, string outputPath)
 {
     return
         (from resourceFileGroup in project.Files.ResourceFiles.GroupBy(resourceFile => ResourceUtility.GetResourceCultureName(resourceFile.Key))
             let culture = resourceFileGroup.Key
             where !string.IsNullOrEmpty(culture)
             let inputFileToMetadata = resourceFileGroup.ToDictionary(r => r.Key, r => GetResourceFileMetadataName(project, r))
             let resourceOutputPath = Path.Combine(outputPath, culture)
             let outputFile = Path.Combine(resourceOutputPath, project.Name + ".resources.dll")
             select new CultureResgenIO(culture, inputFileToMetadata, outputFile)
             ).ToList();
 }
示例#20
0
文件: Command.cs 项目: ibebbs/cli
        public static Command CreateForScript(string commandName, IEnumerable<string> args, Project project, string[] inferredExtensionList)
        {
            var commandSpec = CommandResolver.TryResolveScriptCommandSpec(commandName, args, project, inferredExtensionList);

            if (commandSpec == null)
            {
                throw new CommandUnknownException(commandName);
            }

            var command = new Command(commandSpec);

            return command;
        }
示例#21
0
        /// <summary>
        /// Create <see cref="ExtensionInfo"/> and copy properties from <see cref="Project"/>.
        /// </summary>
        /// <param name="project"></param>
        /// <returns></returns>
        private static ExtensionInfo ToDescriptor(Project project)
        {            
            var descriptor = new ExtensionInfo();
            descriptor.Name = project.Name;
            descriptor.Title = project.Title;
            descriptor.Description = project.Description;
            descriptor.Copyright = project.Copyright;
            descriptor.Authors = project.Authors;
            descriptor.Version = project.Version.ToString();
            descriptor.Dependencies = project.Dependencies.Select(t => t.Name);

            return descriptor;
        }
示例#22
0
        public static ICommand CreateCommandForScript(Project project, string scriptCommandLine, Func<string, string> getVariable)
        {
            var scriptArguments = ParseScriptArguments(project, scriptCommandLine, getVariable);
            if (scriptArguments == null)
            {
                throw new Exception($"ScriptExecutor: failed to parse script \"{scriptCommandLine}\"");
            }

            var inferredExtensions = DetermineInferredScriptExtensions();
            
            return Command
                    .CreateForScript(scriptArguments.First(), scriptArguments.Skip(1), project, inferredExtensions)
                    .WorkingDirectory(project.ProjectDirectory);
        }
示例#23
0
        private static IEnumerable<string> ParseScriptArguments(Project project, string scriptCommandLine, Func<string, string> getVariable)
        {
            var scriptArguments = CommandGrammar.Process(
                scriptCommandLine,
                GetScriptVariable(project, getVariable),
                preserveSurroundingQuotes: false);

            scriptArguments = scriptArguments.Where(argument => !string.IsNullOrEmpty(argument)).ToArray();
            if (scriptArguments.Length == 0)
            {
                return null;
            }

            return scriptArguments;
        }
示例#24
0
        public OutputPathCalculator(
            Project project,
            NuGetFramework framework,
            string runtimeIdentifier,
            string baseOutputPath)
        {
            _project = project;
            _framework = framework;
            _runtimeIdentifier = runtimeIdentifier;

            BaseOutputPath = string.IsNullOrWhiteSpace(baseOutputPath) ? _project.ProjectDirectory : baseOutputPath;

            BaseCompilationOutputPath = string.IsNullOrWhiteSpace(baseOutputPath)
                ? Path.Combine(_project.ProjectDirectory, DirectoryNames.Bin)
                : baseOutputPath;
        }
示例#25
0
 // used in incremental compilation
 public static List<NonCultureResgenIO> GetNonCultureResourcesFromIncludeEntries(
     Project project,
     string intermediateOutputPath,
     CommonCompilerOptions compilationOptions)
 {
     var includeFiles = IncludeFilesResolver.GetIncludeFiles(compilationOptions.EmbedInclude, "/", diagnostics: null);
     return
         (from resourceFile in includeFiles
             let inputFile = resourceFile.SourcePath
             where string.IsNullOrEmpty(ResourceUtility.GetResourceCultureName(inputFile))
             let target = resourceFile.IsCustomTarget ? resourceFile.TargetPath : null
             let metadataName = GetResourceFileMetadataName(project, resourceFile.SourcePath, target)
             let outputFile = ResourceUtility.IsResxFile(inputFile) ? Path.Combine(intermediateOutputPath, metadataName) : null
             select new NonCultureResgenIO(inputFile, outputFile, metadataName)
             ).ToList();
 }
        public GivenThatIWantToLoadAProjectJsonFile()
        {
            var json = new JObject();
            _emptyProject = GetProject(json);
            _jsonCompilationOptions = new JObject();

            _jsonCompilationOptions.Add("define", new JArray(_someDefines));
            _jsonCompilationOptions.Add("nowarn", new JArray(_noWarnings));
            _jsonCompilationOptions.Add("additionalArguments", new JArray(_someAdditionalArguments));
            _jsonCompilationOptions.Add("languageVersion", SomeLanguageVersion);
            _jsonCompilationOptions.Add("outputName", SomeOutputName);
            _jsonCompilationOptions.Add("compilerName", SomeCompilerName);
            _jsonCompilationOptions.Add("platform", SomePlatform);
            _jsonCompilationOptions.Add("keyFile", SomeKeyFile);
            _jsonCompilationOptions.Add("debugType", SomeDebugType);
            _jsonCompilationOptions.Add("allowUnsafe", true);
            _jsonCompilationOptions.Add("warningsAsErrors", true);
            _jsonCompilationOptions.Add("optimize", true);
            _jsonCompilationOptions.Add("delaySign", true);
            _jsonCompilationOptions.Add("publicSign", true);
            _jsonCompilationOptions.Add("emitEntryPoint", true);
            _jsonCompilationOptions.Add("xmlDoc", true);
            _jsonCompilationOptions.Add("preserveCompilationContext", true);

            _commonCompilerOptions = new CommonCompilerOptions
            {
                Defines = _someDefines,
                SuppressWarnings = _noWarnings,
                AdditionalArguments = _someAdditionalArguments,
                LanguageVersion = SomeLanguageVersion,
                OutputName = SomeOutputName,
                CompilerName = SomeCompilerName,
                Platform = SomePlatform,
                KeyFile = SomeKeyFile,
                DebugType = SomeDebugType,
                AllowUnsafe = true,
                WarningsAsErrors = true,
                Optimize = true,
                DelaySign = true,
                PublicSign = true,
                EmitEntryPoint = true,
                GenerateXmlDocumentation = true,
                PreserveCompilationContext = true
            };
        }
示例#27
0
        public CompilationOutputFiles(
            string basePath,
            Project project,
            string configuration,
            NuGetFramework framework)
        {
            BasePath = basePath;
            Project = project;
            Configuration = configuration;
            Framework = framework;
            OutputExtension = FileNameSuffixes.DotNet.DynamicLib;

            var compilationOptions = Project.GetCompilerOptions(framework, configuration);
            if (framework.IsDesktop() && compilationOptions.EmitEntryPoint.GetValueOrDefault())
            {
                OutputExtension = FileNameSuffixes.DotNet.Exe;
            }
        }
示例#28
0
 public PublishCommand(string projectPath,
     string framework = "",
     string runtime = "",
     string output = "",
     string config = "",
     bool noBuild = false,
     string buildBasePath = "")
     : base("dotnet")
 {
     _path = projectPath;
     _project = ProjectReader.GetProject(projectPath);
     _framework = framework;
     _runtime = runtime;
     _output = output;
     _config = config;
     _noBuild = noBuild;
     _buidBasePathDirectory = buildBasePath;
 }
示例#29
0
 public ProjectDescription(
     LibraryRange libraryRange,
     Project project,
     IEnumerable<LibraryRange> dependencies,
     TargetFrameworkInformation targetFrameworkInfo,
     bool resolved) :
         base(
             new LibraryIdentity(project.Name, project.Version, LibraryType.Project),
             string.Empty, // Projects don't have hashes
             project.ProjectFilePath,
             dependencies,
             targetFrameworkInfo.FrameworkName,
             resolved,
             compatible: true)
 {
     Project = project;
     TargetFrameworkInfo = targetFrameworkInfo;
 }
示例#30
0
        public static CommandSpec TryResolveScriptCommandSpec(
            string commandName, 
            IEnumerable<string> args, 
            Project project, 
            string[] inferredExtensionList)
        {
            var commandResolverArgs = new CommandResolverArguments
            {
                CommandName = commandName,
                CommandArguments = args,
                ProjectDirectory = project.ProjectDirectory,
                InferredExtensions = inferredExtensionList
            };

            var scriptCommandResolver = ScriptCommandResolverPolicy.Create();
            
            return scriptCommandResolver.Resolve(commandResolverArgs);
        }