Exemplo n.º 1
0
        private static void ConfigureProcessStartInfoForMethodInvocation(MethodInfo method, string[] args, ProcessStartInfo psi)
        {
            if (method.ReturnType != typeof(void) &&
                method.ReturnType != typeof(int) &&
                method.ReturnType != typeof(Task <int>))
            {
                throw new ArgumentException("method has an invalid return type", nameof(method));
            }
            if (method.GetParameters().Length > 1)
            {
                throw new ArgumentException("method has more than one argument argument", nameof(method));
            }
            if (method.GetParameters().Length == 1 && method.GetParameters()[0].ParameterType != typeof(string[]))
            {
                throw new ArgumentException("method has non string[] argument", nameof(method));
            }

            // If we need the host (if it exists), use it, otherwise target the console app directly.
            Type     t            = method.DeclaringType;
            Assembly a            = t.GetTypeInfo().Assembly;
            string   programArgs  = PasteArguments.Paste(new string[] { a.FullName, t.FullName, method.Name });
            string   functionArgs = PasteArguments.Paste(args);
            string   fullArgs     = HostArguments + " " + " " + programArgs + " " + functionArgs;

            psi.FileName  = HostFilename;
            psi.Arguments = fullArgs;
        }
Exemplo n.º 2
0
        static ExecFunction()
        {
            HostFilename = Process.GetCurrentProcess().MainModule.FileName;

            // application is running as 'dotnet exec'
            if (HostFilename.EndsWith("/dotnet") || HostFilename.EndsWith("\\dotnet.exe"))
            {
                string execFunctionAssembly = typeof(ExecFunction).Assembly.Location;

                string entryAssemblyWithoutExtension = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
                                                                    Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location));
                string[] appArguments = GetApplicationArguments();

                string runtimeConfigFile = GetApplicationArgument(appArguments, "--runtimeconfig");
                if (runtimeConfigFile == null)
                {
                    runtimeConfigFile = entryAssemblyWithoutExtension + ".runtimeconfig.json";
                }

                string depsFile = GetApplicationArgument(appArguments, "--depsfile");
                if (depsFile == null)
                {
                    depsFile = entryAssemblyWithoutExtension + ".deps.json";
                }

                HostArguments = PasteArguments.Paste(new string[] { "exec", "--runtimeconfig", runtimeConfigFile, "--depsfile", depsFile, execFunctionAssembly });
            }
            // application is an apphost. Main method must call 'RunFunction.Program.Main' for CommandName.
            else
            {
                HostArguments = CommandName;
            }
        }
Exemplo n.º 3
0
        static ExecFunction()
        {
            HostFilename = Process.GetCurrentProcess().MainModule.FileName;
            string[] appArguments = null;

            // application is running as 'testhost'
            // try to find parent 'dotnet' host process.
            if (HostFilename.EndsWith("/testhost") || HostFilename.EndsWith("\\testhost.exe"))
            {
                HostFilename = null;

                appArguments = GetApplicationArguments();
                string parentProcessIdRaw = GetApplicationArgument(appArguments, "--parentprocessid");
                if (parentProcessIdRaw != null)
                {
                    int parentProcessId = int.Parse(parentProcessIdRaw);

                    Process proc = Process.GetProcessById(parentProcessId);
                    HostFilename = proc.MainModule.FileName;
                }

                if (HostFilename == null ||
                    !((HostFilename.EndsWith("/dotnet") || HostFilename.EndsWith("\\dotnet.exe"))))
                {
                    throw new NotSupportedException("Application is running as testhost, unable to determine parent 'dotnet' process.");
                }
            }

            // application is running as 'dotnet exec'.
            if (HostFilename.EndsWith("/dotnet") || HostFilename.EndsWith("\\dotnet.exe"))
            {
                string execFunctionAssembly = typeof(ExecFunction).Assembly.Location;

                string entryAssemblyWithoutExtension = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
                                                                    Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location));
                appArguments = appArguments ?? GetApplicationArguments();

                string runtimeConfigFile = GetApplicationArgument(appArguments, "--runtimeconfig");
                if (runtimeConfigFile == null)
                {
                    runtimeConfigFile = entryAssemblyWithoutExtension + ".runtimeconfig.json";
                }

                string depsFile = GetApplicationArgument(appArguments, "--depsfile");
                if (depsFile == null)
                {
                    depsFile = entryAssemblyWithoutExtension + ".deps.json";
                }

                HostArguments = PasteArguments.Paste(new string[] { "exec", "--runtimeconfig", runtimeConfigFile, "--depsfile", depsFile, execFunctionAssembly });
            }
            // application is an apphost. Main method must call 'RunFunction.Program.Main' for CommandName.
            else
            {
                HostArguments = CommandName;
            }
        }