2014-06-17 47 views
2

我开始使用Sublime Text(通过Dropbox在Linux和Windows中同步包文件夹),并且创建了一些不带Visual Studio的小型C#项目。构建系统以将项目目录中的每个* .CS文件编译为一个可执行文件

我可以编译单个文件在Windows cscgmcs在Linux,并且已经与gmsc *.cs,它巧妙地解决了依赖和创建后命名的可执行文件编译的Linux多个文件的命令行(外升华)来源中的“最顶级”课程。

摸索了一下与崇高的文本生成配置文件,同时reading the docs之后,而不是已经了解了,我的问题是:

我应该如何配置崇高文本(通过JSON文件)来构建每一个*的.cs将项目/目录内的文件合并为一个可执行文件?

这些项目,至少现在是非常简单的,我只是分开文件,以保持组织。

+0

是你的问题如何编译与中信建投单呼或别的东西(“CSC /多个CS文件?“应该帮助前者 - 只需指定所有文件)... –

+0

@AlexeiLevenkov是的,我想要执行相同的'gmcs * .cs; mono * .exe',它可以在bash脚本中成功运行,但不是运行脚本,而是将它放在'.build-system'文件中,它应该是这样(但我不知道如何) 。 – heltonbiker

+0

我明白了 - 你的问题是关于我不知道的事情,所以我为什么不理解它。抱歉。 –

回答

1

对于Windows考虑an approach to doing what you want on the Sublime Text forums。虽然它是针对ST2发布的,但我发现它在ST3中也能正常工作。

我认为在阅读构建系统文档后,您会发现海报的特定方法更容易遵循和适应,而不是试图从头开始获得解决方案。

这里是.sublime-build文件的内容 - 与1))的cmd路径为我的Windows环境和2设置$file通过*.cs取代编译当前文件的目录中的所有.cs文件:

{ 
    "cmd": ["C:\\Bin\\Scripts\\sublimetext_csharp_builder.bat", "*.cs", "${file/\\.cs/\\.exe/}"], // NOTE: path set for my Windows environment 
    //"cmd": ["\\path\\to\\sublimetext_csharp_builder.bat", "$file", "${file/\\.cs/\\.exe/}"], 
    "working_dir": "${project_path:${folder:${file_path}}}", 
    "file_regex": "^(...*?)[(]([0-9]*),([0-9]*)[)]", 
    "selector": "source.cs" 
} 

你可以找到the related sublimetext_csharp_builter.bat file on GitHub。下面我只是1)删除了它依赖于Visual Studio批处理文件来设置环境变量,这确实没有必要,只要csc%PATH%中解决,或者使用它的完整路径和2)引用其中的路径产生exe,我认为有必要为我所用的路径(因为它包含空格):

:: Assumptions: 
:: - Sublime Text has set the working directory and both the source and executable files 
:: are in that directory 
:: - The script is only capable of handling simple C# apps that do not reference 3rd-party 
:: libraries 

:: Inputs from Sublime Text 
:: %1 - The full path and filename of the source file to build 
:: %2 - The name of the executable file 
@SET SRC_FILE="%1" 
@SET EXE_NAME="%2" 

csc %SRC_FILE% /nologo /debug:full /platform:x86 
@IF errorlevel 1 GOTO end 

:: Execute compiled binary if build was successful. 
@ECHO. 
@ECHO Executing %EXE_NAME%: 
@ECHO. 
:: NOTE: path quoted to accommodate spaces in it 
@"%EXE_NAME%" 
@%EXE_NAME% 

:end 
+0

@heltonbiker:另外,[博客文章](http://www.jinweijie.com/sublimetext/net-build-system-for-sublime-text-2/)和[与GitHub上的相关代码](https://Jinithijie/sublime- text-2-csharp-build)由金伟杰详细阐述了这个方法 - 也许值得一试,一旦你得到了上述简单的方法满足你的需求。 – J0e3gan

相关问题