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

Joh*_*ohn -3 c# asp.net exe console-application visual-studio-2012

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

C:\>ConsoleApplication1.exe
Run Code Online (Sandbox Code Playgroud)

但是我收到以下错误: -

'ConsoleApplication1.exe' is not recognized as an internal or external command,
operable program or batch file.
Run Code Online (Sandbox Code Playgroud)

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

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();
            }

        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我使用记事本打开.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>
Run Code Online (Sandbox Code Playgroud)

这是我复制的文件: -

在此输入图像描述

gmi*_*ley 6

您可能隐藏了文件扩展名,这意味着您也可能复制ConsoleApplication1.exe.config而不是ConsoleApplication1.exe,但是您应该同时存在于要从中执行程序的文件夹中.复制它时,您可能会复制ConsoleApplication1.exe.configConsoleApplication1.exe,意外删除原始的.config扩展名.

  • @JohnJohn不,你没有.看截图.它具体说明它是一个XML配置文件,意思是你的`.exe.config`,而不是你的`.exe`.`.config`扩展名是隐藏的.转到文件夹选项 - >查看并取消选中"隐藏已知文件类型的扩展名" (2认同)