从命令提示符调用控制台应用程序

calling a console application from a command prompt

我使用 visual studio 2012 创建了一个新的控制台应用程序。然后我导航到项目“...\bin\debug”中的以下位置,并将 .exe 文件复制到 C。 现在我想从命令提示符调用这个 .exe 文件,所以我写了以下内容:-

C:\>ConsoleApplication1.exe

但我收到以下错误:-

'ConsoleApplication1.exe' is not recognized as an internal or external command,
operable program or batch file.

这是我的控制台应用程序主要方法:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {
            using (SkillManagementEntities sd = new SkillManagementEntities())
            {
                sd.Levels.Add(new Level() { Name = "from CA" });
                sd.SaveChanges();
            }

        }
    }
}

如果我使用记事本打开 .exe 文件,我会得到以下内容,其中包含配置而不是实际方法代码...:-

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <connectionStrings>
    <add name="SkillManagementEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost;initial catalog=SkillManagement;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
</configuration>

这是我复制的文件:-

您可能隐藏了文件扩展名,这意味着您也可能复制了 ConsoleApplication1.exe.config 而不是 ConsoleApplication1.exe,但是您应该将两者都放在要从中执行程序的文件夹中。当您复制它时,您可能会复制 ConsoleApplication1.exe.configConsoleApplication1.exe,不小心删除了原始的 .config 扩展名。