简体   繁体   中英

Windows Store Project - Assembly reference error when trying to run cmd commands from a C# file in VS2012

I'm doing some exercises with C# in the trial version of VS 2012. I want to execute a cmd command from a CS file. For this, I've tried Process.Start as well as System.Diagnostics.Process that are mentioned in these posts:

Run Command Prompt Commands

Execute CMD command from code

However, despite I added "using System.Diagnostics" and "using System.ComponentModel", I'm still getting "The type or namespace name 'Process' does not exist in the namespace 'System.Diagnostics', missing assembly reference" error. ¿Any suggestion so I can i get rid of this error? Thanks in advance.

This usually happens when you have Target framework = .NET Framework Client Profile, but DLL you reference is from .NET Framework (full). Make sure you have System.dll in your references from valid framework.

I just did the same - created empty console application with the following code:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var prc = Process.Start("explorer.exe");
        }
    }
}

Works perfectly fine for me.

Additional thing to check is Intellisense - when you start typing "System.Diagnostics.Proc"... - does it show you dropdown with "Process" there?

UPDATE: Windows Store projects are based on different version of target .NET Framework - .NET for Windows Store apps , which does not support functionality you need.

For more details do web search:".NET for Windows Store apps". Helpful links:

http://msdn.microsoft.com/en-us/library/windows/apps/br230302.aspx

http://msdn.microsoft.com/en-us/library/windows/apps/br230232.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM