【问题标题】:calling a console application from a command prompt从命令提示符调用控制台应用程序
【发布时间】:2016-01-12 18:17:27
【问题描述】:

我使用 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>

这是我复制的文件:-

【问题讨论】:

  • 您确定这是命令提示符而不是 powershell 提示符吗?试试:.\ConsoleApplication1.exe
  • 您确定复制的是 EXE 而不是 EXE.CONFIG 文件? (关注hide well known file extension配置)
  • 输入C:\&gt;dir 并检查ConsoleApplication1.exe 是否在列表中
  • "如果我使用记事本打开 .exe 文件,我将得到以下内容,其中包含配置而不是实际的方法代码":查看记事本中的标题栏.它说什么?我敢打赌,正如其他人所建议的那样,它会说 ConsoleApplication1.exe.config
  • @JohnJohn:你再检查一遍,因为你已经很清楚地复制了错误的文件。记事本中的标题栏将有.exe.config。查看类型为“应用程序”的那个。那是你的exe文件。您正在隐藏扩展(这是 Windows 恕我直言的一个非常烦人的“功能”)

标签: c# asp.net visual-studio-2012 console-application exe


【解决方案1】:

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

【讨论】:

  • 不,我复制了 .exe 文件,您能否再次检查我的问题? /跨度>
  • @JohnJohn 不,你没有。看截图。它明确表示这是一个 XML 配置文件,这意味着这是您的 .exe.config,而不是您的 .exe.config 扩展是隐藏的。转到文件夹选项->查看并取消选中Hide extensions for known file types
  • @gmiley 现在我想将 .application 文件移动到另一台服务器,所以我需要复制哪个文件,因为如果我直接从我的项目文件夹运行 .application 文件,它将起作用,,但是如果我将它复制到 c 驱动器然后我运行它,我会得到一个错误“未处理的异常.. system.io.filenotfound 无法加载文件或程序集'实体框架”,所以不确定我需要做什么我想将 .application 文件移动到另一台服务器..
  • @JohnJohn 这是一个单独的问题,请不要移动目标帖子。既然这个问题已经解决,我建议接受这个答案。
  • @JohnJohn: 也复制EntityFramework.dll 和其他文件。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-14
  • 1970-01-01
  • 2012-09-01
  • 2010-11-02
  • 2020-05-12
相关资源
最近更新 更多