2017-03-22 64 views
3

我使用的Visual Studio代碼,因爲它比Visual Studio更輕,但仍然給我intellisense。然而,我找不到Code自動生成.csproj或.sln的方法,因此我一直在創建這些文件。關於它的文檔很少,所以我不得不脫離其他文件的示例。這一切都很好,但最近我遇到了一個麻煩,那就是用msbuild編譯它並沒有給出與csc.exe編譯相同的結果。每當我加載一個dll並嘗試使用它的一個類時,我會得到一個BadImageFormatException。我的問題是,有沒有辦法讓vscode在創建新項目時生成csproj或sln文件?如果沒有,是否有辦法使我編譯的csproj文件與我使用批處理文件一樣編譯?vscode是否有csproj生成器?

的csproj文件:

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
<ItemGroup> 
    <Reference Include="System" /> 
    <Reference Include="System.Drawing" /> 
    <Reference Include="Splicer.dll"> 
     <HintPath>Splicer.dll</HintPath> 
    </Reference> 
    <Reference Include="DirectShowLib-2005.dll"> 
     <HintPath>DirectShowLib-2005.dll</HintPath> 
    </Reference> 
    <Compile Include="src\*.cs" /> 
</ItemGroup> 
<Target Name="Build"> 
    <MakeDir Directories="$(OutputPath)" 
     Condition="!Exists('$(OutputPath)')" 
    /> 
    <Csc 
     Platform="x86" 
     NoWarn="" 
     Sources="@(Compile)" 
     OutputAssembly="$(OutputPath)$(AssemblyName).exe" 
    /> 
</Target> 
<PropertyGroup> 
    <AssemblyName>SplicerDemo</AssemblyName> 
    <OutputPath>bin\</OutputPath> 
</PropertyGroup> 
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 

批處理編譯器:

@echo off 
set "CSC=C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe" 
set "Refs=Splicer.dll,DirectShowLib-2005.dll" 
set "Files=src\SplicerDemo\*.cs" 
set "Compile=%csc% /platform:x86 /r:%Refs% /out:SplicerDemo.exe /t:exe %Files$" 
cmd 

文件編譯:

using Splicer.Renderer; 
using Splicer.Timeline; 

using System.Drawing; 

namespace SplicerDemo { 
    public class Start { 
     // Variables 
     public string outputFile; 

     public Start() { 
      outputFile= "Foo.avi"; 
     } 

     public static void Main() { 
      Start s= new Start(); 

      System.Console.WriteLine("Starting Build..."); 
      s.save(); 
      System.Console.WriteLine("Build Finished!"); 
     } 

     // --- Methods --- 

     public void save() { 
      // Variables 
      DefaultTimeline timeline= new DefaultTimeline(24); 
      IGroup _group= timeline.AddVideoGroup(32, 1024, 786); 
      ITrack vtrack= _group.AddTrack(); 
      ITrack atrack= timeline.AddAudioGroup().AddTrack(); 
      Bitmap img= new Bitmap("image3.jpg"); 

      vtrack.AddImage("image1.jpg", 0, 24); 
      vtrack.AddImage("image2.jpg", 0, 24); 
      vtrack.AddImage(img, 0, 100); 
      vtrack.AddImage("image1.jpg", 0, 128); 

      atrack.AddAudio("audio1.mp3", 0, vtrack.Duration); 

      using(AviFileRenderer renderer= new AviFileRenderer(timeline, outputFile)) { 
       renderer.Render(); 
      } 
     } 
    } 
} 

回答

2

可惜VSCode沒有辦法建立/編譯解決方案/項目但是它確實支持針對.Net Core的項目。您可以使用Yeoman項目腳手架系統創建和構建以.Net Core爲目標的項目。

相關問題