简体   繁体   English

在Visual Studio中运行文件的任何快速方法?

[英]Any quick way to run a file in Visual Studio?

Is there any quick way to run a file(.cs) in VS 2008 with a Main method ? 有没有快速方法在VS 2008中使用Main方法运行文件(.cs)?

Often you'd want to test some mockup code, Going Alt+f7(Project->ProjectName Properties) and changing the Startup object from a dropdown list is quite cumbersome. 通常,您需要测试一些模型代码,Going Alt + f7(Project-> ProjectName Properties)并从下拉列表中更改Startup对象非常麻烦。

让自己成为SnippetCompiler ,它可以运行片段(不在VS内部,但足够接近)并且可以帮助你。

What about instead of mockups, writing those as unit tests. 那些代替模型,把它们写成单元测试。 You can run those quickly without changing entry points. 您可以快速运行它们而无需更改入口点。 And the tests could stick around for later changes. 测试可以留待以后的更改。 Instead of writing to the Console, you would use Asserts and Trace Writes. 您可以使用Asserts和Trace Writes,而不是写入控制台。

To compile one file C# programs I have created a .bat file, on which I drag and drop a .cs file and get a .exe in .cs file directory. 为了编译一个文件C#程序,我创建了一个.bat文件,在该文件中我拖放.cs文件并在.cs文件目录中获取.exe文件。

SET PATH=%PATH%;C:\WINDOWS\Microsoft.NET\Framework\v3.5
cd %~d1\
cd "%~p1"
csc %1

You can use this .bat file in a Visual Studio macro to compile active .cs file and run the application. 您可以在Visual Studio宏中使用此.bat文件来编译活动的.cs文件并运行该应用程序。

Sub RunCS()
    If Not ActiveDocument.FullName.EndsWith(".cs") Then
        Return
    End If
    REM Path to batch file
    Dim compileScript = "C:\dev\compileCS.bat"

    Dim compileParams As System.Diagnostics.ProcessStartInfo
    compileParams = New ProcessStartInfo(compileScript, Chr(34) & ActiveDocument.FullName & Chr(34))

    Dim compiling As System.Diagnostics.Process

    compiling = System.Diagnostics.Process.Start(compileParams)
    compiling.WaitForExit()

    Dim programFile As String
    programFile = ActiveDocument.FullName.Substring(0, ActiveDocument.FullName.Length - 3) + ".exe"

    Dim running As System.Diagnostics.Process
    running = System.Diagnostics.Process.Start(programFile)

End Sub

This will run only programs for which all code is in one file. 这将只运行所有代码都在一个文件中的程序。 If you want to quickly change projects instead, you can change your solution's Startup Project to Current selection 如果您想快速更改项目,可以将解决方案的启动项目更改为当前选择

I keep a sandbox solution around that has a console project and other tiny project types that I use frequently. 我保留了一个沙盒解决方案,它有一个控制台项目和我经常使用的其他小项目类型。 Snippet Tools are nice but usually don't come with the whole Visual Studio shebang like debugging etc. Snippet Tools很不错,但通常不会像调试等整个Visual Studio一样。

Snippy ,最初由Jon Skeet(我相信潜伏在这里)并由Jason Haley进一步开发。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有什么方法可以检查解决方案中的某处是否引用了 css 文件? 视觉工作室 - Any way to check if a css file is referenced somewhere in the solution? Visual Studio 有什么方法可以从Visual Studio中的“资源”文件中“窥视”值? - Is there any way to 'peek' a value from a Resources file in Visual Studio? 有什么方法可以在 Visual Studio 中进行快速一次性编译,而无需创建全新的 Proj/Solution? - Any way to do quick one-off compilations from within Visual Studio without the need to create an entirely new Proj/Solution? 有什么快速方法可以将 Visual Studio Ultimate/Enterprise 版降级到 Professional? - Any quick ways to downgrade Visual Studio Ultimate/Enterprise edition to Professional? 是否有任何Visual Studio扩展使Quick Watch对话框更智能? - Is there any Visual Studio extension making Quick Watch dialog smarter? 在Visual Studio 2005中将接口方法插入类的快速方法 - Quick way to insert interface methods to a class in Visual Studio 2005 在Visual Studio中,有没有一种快速的方法来生成这些类型的注释块? - In Visual Studio, is there a quick way to generate these types of comment blocks? 有没有一种快速方法可以消除Visual Studio中C程序中未使用的类型? - Is there an quick way to eliminate unused types in a C program in Visual Studio? 在 Visual Studio 2010 中是否有快速切换解决方案平台的方法? - Is there a quick way to switch the solution platform in Visual Studio 2010? 在Visual Studio中按选项卡窗口中的文件类型快速排序 - Order by file type in Visual Studio quick switch between tabs window
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM