dotnet / dotnet/vscode-csharp

Question: (code-gen) is there a way to trigger a design time build when non-source files are saved?

Open
#3,855 0 comments 0 reactions 0 assignees View on GitHub
OmniSharp Project System Triaged
Dominant language
TypeScript
Stars
3.1k
Forks
737
Avg merge
17h 56m
Merged PRs (30d)
21

Description

## Issue Description ##

In Visual Studio it is possible to have a file edit trigger a design time build. This is done by adding `MSBuild:Compile ` metadata to an ItemGroup in MSBuild. Then, when such a file is edited/saved, it will trigger the compile target, and run any dependent targets. Such a target would typically emit C# source files in the obj folder and include them in the `Compile` group. The generated source would then ~immediately be visible in intellisense listings in VS.

This mechanism doesn't appear to work in VSCode though. The only way I've found to trigger a design time build is to save the .csproj file; it doesn't require an edit, just a no-op save does the trick. This is less than ideal user-experience though. Is there a different mechanism that can be used to cause a non-source file-save to trigger a design time build in Omnisharp?

## Steps to Reproduce ##

Clone this repository containing a minimal repro:
https://github.com/MarkPflug/CodeGenExample

Open the csproj in Visual Studio. Edit the Text.gen file: change the member name from "Foo" to "Bar". Open Program.cs, notice that intellisense immediate reflects the change of member name: "Foo" now shows as an error.

Do the same thing in VSCode. Note how the member rename is not immediately reflected in intellisense. Open and save the .csproj file. Notice that the member rename is now visible to intellisense after saving the csproj.

## Expected Behavior ##
No expectation, really, this is just a question about whether there is some mechanism I can use to trigger a design-time build in OmniSharp when a file like "Text.gen" file is saved?

## Actual Behavior ##

## Logs ##

### OmniSharp log ###

### C# log ###

## Environment information ##

**VSCode version**: 1.46.0
**C# Extension**: 1.22.1

Dotnet Information
.NET Core SDK (reflecting any global.json):
Version: 3.1.300
Commit: b2475c1295

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19041
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.300\

Host (useful for support):
Version: 3.1.4
Commit: 0c2e69caa6

.NET Core SDKs installed:
3.0.100 [C:\Program Files\dotnet\sdk]
3.1.101 [C:\Program Files\dotnet\sdk]
3.1.300 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

Visual Studio Code Extensions

|Extension|Author|Version|
|---|---|---|
|cpptools|ms-vscode|0.28.3|
|csharp|ms-dotnettools|1.22.1|
|dart-code|Dart-Code|3.11.0|
|remote-wsl|ms-vscode-remote|0.44.3|;

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.