[英]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.