Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在不涉及Visual Studio的情况下编译C解决方案?_C#_Asp.net_Visual Studio 2010_Batch File_Aspnet Compiler - Fatal编程技术网

C# 如何在不涉及Visual Studio的情况下编译C解决方案?

C# 如何在不涉及Visual Studio的情况下编译C解决方案?,c#,asp.net,visual-studio-2010,batch-file,aspnet-compiler,C#,Asp.net,Visual Studio 2010,Batch File,Aspnet Compiler,我一点也不特别喜欢VisualStudio,宁愿使用高度配置的gvim来编辑代码,也不愿被限制在IDE中 因此,我的目标是找到一种为web应用程序编译C代码的方法,而不需要一个膨胀的>2gb的怪物,我只需要偶尔使用它 目前,我可以使用以下批处理脚本编译现有代码: 这个问题需要一个项目文件和一个解决方案文件。如果我可以获得Visual Studio使用的现有脚本,我可以在自动脚本中使用远程计算机的副本,或者自己生成它们,是否有办法隔离这些脚本的生成方式 或者,对于较小的项目和单个表单,是否有办法

我一点也不特别喜欢VisualStudio,宁愿使用高度配置的gvim来编辑代码,也不愿被限制在IDE中

因此,我的目标是找到一种为web应用程序编译C代码的方法,而不需要一个膨胀的>2gb的怪物,我只需要偶尔使用它

目前,我可以使用以下批处理脚本编译现有代码:

这个问题需要一个项目文件和一个解决方案文件。如果我可以获得Visual Studio使用的现有脚本,我可以在自动脚本中使用远程计算机的副本,或者自己生成它们,是否有办法隔离这些脚本的生成方式

或者,对于较小的项目和单个表单,是否有办法绕过它们?不幸的是,我对aspnet_编译器的了解有限。

Microsoft.Build命名空间是您的朋友

示例:制作csproj:

var pathToLibs = @"..\..\..\libs\";

Engine engine=new Engine();
engine.BinPath=RuntimeEnvironment.GetRuntimeDirectory();

Project project=engine.CreateNewProject();    
project.AddNewImport(@"$(MSBuildBinPath)\Microsoft.CSharp.targets", null);

BuildPropertyGroup props=project.AddNewPropertyGroup(false);
props.AddNewProperty("AssemblyName", "myassembly");
props.AddNewProperty("OutputType", "Library");

BuildItemGroup items=project.AddNewItemGroup();    
var asmRef = items.AddNewItem("Reference", "SomLibFile");
asmRef.SetMetadata("HintPath", Path.Combine(pathToLibs, @"SomeLibFile.dll"));
items.AddNewItem("Compile", "somefile.cs");

project.Save(@"c:\temp\myproject.csproj");
从解决方案.sln文件生成元项目文件:

var foo = SolutionWrapperProject.Generate(
   @"path.to.my.sln", 
    "4.0", 
    null);
翻找,翻找啊哈——我知道我身边有这个;实际生成生成的元项目/解决方案文件的项目示例:

var solutionProjects = 
    from buildLevel in Enumerable.Range(0, 10)
    let buildLevelType = "BuildLevel" + buildLevel
    let buildLevelItems = slnProj.GetItems(buildLevelType)
    from buildLevelItem in buildLevelItems
    let include = buildLevelItem.EvaluatedInclude
    where !(include.Contains("UnitTests") || include.Contains("Unit Tests"))            
    select new { Include=include, Project = pc.LoadProject(Path.Combine(basePath, include))};

foreach (var projectPair in solutionProjects)
{
    var project = projectPair.Project;
    string.Format("OutDir={0}", project.ExpandString("$(OutDir)")).Dump();
    string.Format("OutputPath={0}", project.ExpandString("$(OutputPath)")).Dump();
    continue;
    var include = projectPair.Include;
    var outputPath = outputDir;
    project.SetProperty("OutputPath", outputPath);
    var projectLogger = new BasicFileLogger();    
    var tempProjectLogPath = Path.GetTempFileName();
    projectLogger.Parameters = tempProjectLogPath ;

    Console.WriteLine("Building project:" + project.DirectoryPath);
    var buildOk = project.Build("Build", new[]{projectLogger});
    if(buildOk)
    {
        Console.WriteLine("Project build success!");
    } 
    else
    {
        var logDump = File.ReadAllText(tempProjectLogPath);
        logDump.Dump();
        throw new Exception("Build failed");
    }
}

我相信您可以在不抨击IDE的情况下提出这个问题。Visual Studio做了什么伤害了你的感情?对不起x.x.我是Linux用户-我有点习惯于使用更小的,无可否认,由于我在Windows上工作,我不得不使用gvim而不是vim,而且安装的IDE可能超过4gb,这让我有些恐惧。看看你的意思,也许你是说让我不知所措,而不是让我感到恐惧。@LaniAlden没问题:。顺便说一句我的手机有超过4gb的存储空间。时代变了,非常感谢!这对我帮助很大!没问题!对于在构建服务器上动态生成和构建项目来说,这种类型的东西也是黄金;我已经写了上面的十几个变体…: