private static CSharpCompilationOptions AddSigningOptions(CSharpCompilationOptions options, ICompilerOptions compilerOptions, string projectDirectory)
        {
            var useOssSigning = compilerOptions.UseOssSigning == true;

            var keyFile =
                Environment.GetEnvironmentVariable(EnvironmentNames.BuildKeyFile) ??
                GetKeyFileFullPath(projectDirectory, compilerOptions.KeyFile);

            if (!string.IsNullOrWhiteSpace(keyFile))
            {
#if DOTNET5_4
                return(options.WithCryptoPublicKey(
                           SnkUtils.ExtractPublicKey(File.ReadAllBytes(keyFile))));
#else
                if (RuntimeEnvironmentHelper.IsMono || useOssSigning)
                {
                    return(options.WithCryptoPublicKey(
                               SnkUtils.ExtractPublicKey(File.ReadAllBytes(keyFile))));
                }

                options = options.WithCryptoKeyFile(keyFile);

                var delaySignString = Environment.GetEnvironmentVariable(EnvironmentNames.BuildDelaySign);
                var delaySign       =
                    delaySignString == null
                        ? compilerOptions.DelaySign
                        : string.Equals(delaySignString, "true", StringComparison.OrdinalIgnoreCase) ||
                    string.Equals(delaySignString, "1", StringComparison.Ordinal);

                return(options.WithDelaySign(delaySign));
#endif
            }

            return(useOssSigning ? options.WithCryptoPublicKey(StrongNameKey) : options);
        }
        public void WithCryptoPublicKey()
        {
            var options = new CSharpCompilationOptions(OutputKind.ConsoleApplication);

            Assert.Equal(ImmutableArray <byte> .Empty, options.CryptoPublicKey);
            Assert.Equal(ImmutableArray <byte> .Empty, options.WithCryptoPublicKey(default(ImmutableArray <byte>)).CryptoPublicKey);

            Assert.Same(options, options.WithCryptoPublicKey(default(ImmutableArray <byte>)));
            Assert.Same(options, options.WithCryptoPublicKey(ImmutableArray <byte> .Empty));
        }
        private static CSharpCompilationOptions AddSigningOptions(CSharpCompilationOptions options, CommonCompilerOptions compilerOptions, string projectDirectory)
        {
            var useOssSigning = compilerOptions.PublicSign == true;
            var keyFile       = compilerOptions.KeyFile;

            if (!string.IsNullOrEmpty(keyFile))
            {
                keyFile = Path.GetFullPath(Path.Combine(projectDirectory, compilerOptions.KeyFile));

                if (
#if !NET451
                    !RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ||
#endif
                    useOssSigning)
                {
                    return(options.WithCryptoPublicKey(
                               SnkUtils.ExtractPublicKey(File.ReadAllBytes(keyFile))));
                }

                options = options.WithCryptoKeyFile(keyFile);

                return(options.WithDelaySign(compilerOptions.DelaySign));
            }

            return(options);
        }
Esempio n. 4
0
        private static CSharpCompilationOptions AddSigningOptions(CSharpCompilationOptions options, CommonCompilerOptions compilerOptions, string projectDirectory)
        {
            var useOssSigning = compilerOptions.PublicSign == true;
            var keyFile       = compilerOptions.KeyFile;

            if (!string.IsNullOrEmpty(keyFile))
            {
                keyFile = Path.GetFullPath(Path.Combine(projectDirectory, compilerOptions.KeyFile));

                if (RuntimeEnvironment.OperatingSystemPlatform != InternalAbstractions.Platform.Windows || useOssSigning)
                {
                    return(options.WithCryptoPublicKey(
                               SnkUtils.ExtractPublicKey(File.ReadAllBytes(keyFile))));
                }

                options = options.WithCryptoKeyFile(keyFile);

                return(options.WithDelaySign(compilerOptions.DelaySign));
            }

            return(options);
        }
Esempio n. 5
0
        private static CSharpCompilationOptions AddSigningOptions(CSharpCompilationOptions options, CommonCompilerOptions compilerOptions, string projectDirectory)
        {
            var useOssSigning = compilerOptions.UseOssSigning == true;
            var keyFile = compilerOptions.KeyFile;

            if (!string.IsNullOrEmpty(keyFile))
            {
                keyFile = Path.GetFullPath(Path.Combine(projectDirectory, compilerOptions.KeyFile));

                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || useOssSigning)
                {
                    return options.WithCryptoPublicKey(
                        SnkUtils.ExtractPublicKey(File.ReadAllBytes(keyFile)));
                }

                options = options.WithCryptoKeyFile(keyFile);

                return options.WithDelaySign(compilerOptions.DelaySign);
            }

            return options;
        }
        private static CSharpCompilationOptions AddSigningOptions(CSharpCompilationOptions options, CommonCompilerOptions compilerOptions, string projectDirectory)
        {
            var useOssSigning = compilerOptions.PublicSign == true;
            var keyFile = compilerOptions.KeyFile;

            if (!string.IsNullOrEmpty(keyFile))
            {
                keyFile = Path.GetFullPath(Path.Combine(projectDirectory, compilerOptions.KeyFile));

                if (RuntimeEnvironment.OperatingSystemPlatform != InternalAbstractions.Platform.Windows || useOssSigning)
                {
                    return options.WithCryptoPublicKey(
                        SnkUtils.ExtractPublicKey(File.ReadAllBytes(keyFile)));
                }

                options = options.WithCryptoKeyFile(keyFile);

                return options.WithDelaySign(compilerOptions.DelaySign);
            }

            return options;
        }
        private static CSharpCompilationOptions AddSigningOptions(CSharpCompilationOptions options, ICompilerOptions compilerOptions, string projectDirectory)
        {
            var useOssSigning = compilerOptions.UseOssSigning == true;

            var keyFile =
                Environment.GetEnvironmentVariable(EnvironmentNames.BuildKeyFile) ??
                GetKeyFileFullPath(projectDirectory, compilerOptions.KeyFile);

            if (!string.IsNullOrWhiteSpace(keyFile))
            {
#if DOTNET5_4
                return options.WithCryptoPublicKey(
                    SnkUtils.ExtractPublicKey(File.ReadAllBytes(keyFile)));
#else
                if (RuntimeEnvironmentHelper.IsMono || useOssSigning)
                {
                    return options.WithCryptoPublicKey(
                        SnkUtils.ExtractPublicKey(File.ReadAllBytes(keyFile)));
                }

                options = options.WithCryptoKeyFile(keyFile);

                var delaySignString = Environment.GetEnvironmentVariable(EnvironmentNames.BuildDelaySign);
                var delaySign =
                    delaySignString == null
                        ? compilerOptions.DelaySign
                        : string.Equals(delaySignString, "true", StringComparison.OrdinalIgnoreCase) ||
                            string.Equals(delaySignString, "1", StringComparison.Ordinal);

                return options.WithDelaySign(delaySign);
#endif
            }

            return useOssSigning ? options.WithCryptoPublicKey(StrongNameKey) : options;
        }