2017-03-22 2 views
3

J'utilise Visual Studio Code car il est plus léger que Visual Studio mais me donne quand même l'intellisense. Cependant, je ne pouvais pas trouver un moyen pour que Code construise automatiquement un fichier .csproj ou .sln, donc j'ai fait les fichiers à zéro. Il y a peu de documentation à ce sujet, donc j'ai dû sortir des exemples d'autres fichiers. Tout était bon et bon, mais récemment j'ai trouvé un hic où la compilation avec msbuild ne me donne pas le même résultat que la compilation par csc.exe. J'obtiendrais une exception BadImageFormatException chaque fois que je chargerais dans une DLL et j'essaierais d'utiliser l'une de ses classes. Ma question est, y at-il un moyen d'avoir vscode générer un fichier csproj ou sln que je crée de nouveaux projets? Et si ce n'est pas le cas, y a-t-il un moyen de créer les fichiers csproj que j'ai compilés de la même manière que les fichiers batch?Est-ce que vscode a un générateur csproj?

fichier 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" /> 

Lot compilateur:

@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 

Fichier pour compiler:

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(); 
      } 
     } 
    } 
} 

Répondre

2

Malheureusement VSCode n'a pas moyen de créer/construire solutions/projet s ciblant le framework .Net complet, mais il prend en charge les projets ciblant .Net Core. Vous pouvez utiliser le système d'échafaudage de projet Yeoman pour créer et construire des projets ciblant .Net Core.