我正在使用Visual Studio Code,因为它比Visual Studio更轻量级但仍然给我智能感知。但是我无法找到Code自动构建.csproj或.sln的方法,所以我一直在制作文件。关于它的文档很少,所以我不得不从其他文件中删除示例。这一切都很好,但最近我遇到了一个问题,用msbuild编译它并没有给我与csc.exe编译相同的结果。每当我加载一个DLL并尝试使用它的一个类时,我会得到一个BadImageFormatException。我的问题是,有没有办法让vscode在创建新项目时生成csproj或sln文件?如果没有,有没有办法制作我编译的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();
}
}
}
}
答案 0 :(得分:2)
不幸的是,VSCode没有办法创建/构建针对完整.Net Framework的解决方案/项目,但它确实支持针对.Net Core的项目。您可以使用Yeoman项目脚手架系统来创建和构建以.Net Core为目标的项目。