0

私は Visual Studio がまったく好きではなく、IDE に隔離されるよりも、高度に構成された gvim を使用してコードを編集したいと考えています。

そのため、Web アプリケーション用の C# コードをコンパイルする方法を目指しています。

現在、次のバッチ スクリプトを使用して既存のコードをコンパイルできます: http://www.codeproject.com/Questions/495608/howplustopluspublishplussiteplususingplusaspnet_co

この問題には、プロジェクト ファイルとソリューション ファイルが必要です。これらの生成方法を分離する方法はありますか (Visual Studio が使用する既存のスクリプトを取得できれば、自動化されたスクリプトでリモート マシンのコピーを使用できます)、または自分で生成する方法はありますか?

または、代わりに、小規模なプロジェクトや個々のフォームでそれらをバイパスする方法はありますか? 残念ながら、aspnet_compiler に関する私の知識は限られています。

4

1 に答える 1

7

名前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");
    }
}
于 2013-01-16T00:26:58.227 に答える