Does vscode have a csproj generator?
Asked Answered
A

2

6

I am using Visual Studio Code because it is more lightweight than Visual Studio but still gives me the intellisense. However I could not find a way for Code to build a .csproj or .sln automatically, so I have been making the files by scratch. There is little documentation on it so I had to go off of examples from other files. It was all good and fine, but recently I hit a snag where compiling it with msbuild does not give me the same result as compiling by csc.exe. I would get a BadImageFormatException whenever I would load in a dll and try and use one of it's classes. My question is, is there a way to have vscode generate a csproj or sln file as I create new projects? And if there isn't, is there a way around having to make the csproj files I have compile in the same fashion as I do with the batch files?

csproj file:

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

Batch Compiler:

@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

File to Compile:

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();
            }
        }
    }
}
Antre answered 22/3, 2017 at 23:18 Comment(0)
E
2

Unfortunately VSCode doesn't have way to create/build solutions/projects targeting full .Net Framework however it does have support for projects targeting .Net Core. You can use Yeoman project scaffolding system to create and build projects targeting .Net Core.

Ethiopian answered 23/3, 2017 at 0:1 Comment(0)
B
1

The new C# Dev Kit extension from Microsoft will create .sln and .csproj files for you.

Detailed instructions are here, currently, but here's the quick version:

Install the C# Dev Kit extension, then follow the instructions from the docs, above:

  1. Bring up the Command Palette using ⇧⌘P and then type ".NET".
  2. Find and select the .NET: New Project command.
  3. After selecting the command, you'll need to choose the project template. Choose Console app.
  4. To run your app, select Run > Start Debugging in the upper menu, or use the F5 keyboard shortcut.

Interface is kinda mvp right now, but it works.

Babel answered 30/10, 2023 at 1:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.