【发布时间】: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="data source=localhost;initial catalog=SkillManagement;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" 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:\>dir并检查ConsoleApplication1.exe是否在列表中 -
"如果我使用记事本打开 .exe 文件,我将得到以下内容,其中包含配置而不是实际的方法代码":查看记事本中的标题栏.它说什么?我敢打赌,正如其他人所建议的那样,它会说
ConsoleApplication1.exe.config -
@JohnJohn:你再检查一遍,因为你已经很清楚地复制了错误的文件。记事本中的标题栏将有
.exe.config。查看类型为“应用程序”的那个。那是你的exe文件。您正在隐藏扩展(这是 Windows 恕我直言的一个非常烦人的“功能”)
标签: c# asp.net visual-studio-2012 console-application exe