dotnet / project-system

The .NET Project System for Visual Studio
MIT License
971 stars 388 forks source link

VS Solution Explorer does not show certain folders in a very simple custom SDK style project #7941

Closed MarkKharitonov closed 2 years ago

MarkKharitonov commented 2 years ago

Visual Studio version Microsoft Visual Studio Enterprise 2022 (64-bit) Version 17.0.4

Description I have a very simple custom SDK style project here (https://github.com/MarkKharitonov/HiddenFolders):

C:.
│   .gitignore
│   Directory.Build.props
│   Directory.Build.targets
│   LegacyFrontEnd.sln
│
└───Approvals
    │   Approvals.csproj
    │
    ├───Content
    │       approvals_icons.png
    │
    ├───Scripts
    │       Approvals.ts
    │
    └───StaticViews
            Approvals.html

My problem is that VS Solution Explorer does not show the Scripts folder:

image

The build code is trivial, but it replaces the standard build targets of the SDK:

Directory.Build.props

<Project>
  <PropertyGroup>
    <EnableDefaultItems>False</EnableDefaultItems>
    <GenerateAssemblyInfo>False</GenerateAssemblyInfo>
  </PropertyGroup>
  <ItemGroup>
    <TypeScriptCompile Include="Scripts\**\*.ts" />
    <Stylus Include="Stylus\**\*.styl" />
    <Content Include="Content\**\*.*" />
    <Content Include="StaticViews\**\*.*" />
  </ItemGroup>
</Project>

Directory.Build.targets

<Project>
  <Target Name="Build" />
  <Target Name="Clean" />
  <Target Name="Rebuild" DependsOnTargets="Clean;Build" />

  <Target Name="CompileTypeScript" BeforeTargets="Build">
    <MakeDir Directories="$(MSBuildProjectDirectory)\_jsCompiled"/>
    <Touch Files="$(MSBuildProjectDirectory)\_jsCompiled\Approvals.js" AlwaysCreate="true" />
  </Target>
</Project>

.\Approvals\Approvals.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
    <OutputPath>bin</OutputPath>
  </PropertyGroup>
</Project>

Very simple.

Why does VS Solution Explorer not show the Scripts folder?

P.S.

Also posted here - https://stackoverflow.com/questions/71164341/why-visual-studio-hides-certain-folders-in-a-codeless-c-sharp-project

tmeschter commented 2 years ago

It looks like you're trying to use the .NET SDK for something that is fundamentally not a .NET project as it has no C# (or VB or F#) source files and replaces the default Build behavior entirely. That's likely to break all sorts of assumptions the .NET Project System has about the project and how it works.

In general the Project System does not surface every MSBuild item in the Solution Explorer--that would be a lot of items, many of them irrelevant and confusing as they are an internal detail of the SDK. The Project System knows what Content items are and how they behave (or at least how they behave by default in the .NET SDK) and so they are surfaced in the Solution Explorer; TypeScriptCompile and Stylus items are not known to the Project System, so they aren't shown.

What is it you are trying to achieve that you can't with a typical ASP.NET Core project?

MarkKharitonov commented 2 years ago

We have an old enterprise application. It used to have 50 Asp.Net projects, but not because these projects represented a web application each. No, they just implemented different aspects of one big web application. During the build, these "fake" web applications build the Typescript and Stylus files using ad-hoc targets that run before Build and copy the products to the big web application. We have downgraded these "fake" web applications to normal C# projects, but the fact that they mix C# and Typescript is problematic for us. So, we want to separate them - C# aside, legacy front end code aside. I call it legacy, because at the same time the front end is being migrated to React micro frontends. But right now there is a ton of legacy front end code and it would take literally years to migrate it all (it took us about 10 years to get rid of the Silverlight completely).

So, I am trying to figure out what project format to use for the legacy front end code. Right now, the SDK style projects is the best option I can see. The project files are small and the build code is injected through Directory.Build.* files (of course, the real files are more sophisticated than in my repro). The command line build using msbuild works great. But the VS IDE experience is a problem.

I am open to suggestions, but I cannot change the paradigm where front end code from many different projects is copied to a single location during the build, which corresponds to the location of the big web application.

If I could "tell" VS to show the Scripts folder that would have been the easiest.

drewnoakes commented 2 years ago

If I could "tell" VS to show the Scripts folder that would have been the easiest.

MSBuild projects produce many many items of different types. It does not show all these items in Solution Explorer. It only shows certain types.

TypeScriptCompile items are not shown. If you want to see them in the tree, you'll have to add them as a different type. For example:

<ItemGroup>
   <None Include="@(TypeScriptCompile)" />
</ItemGroup>
drewnoakes commented 2 years ago

Actually, a simpler approach may be for you to use this instead:

<ItemGroup>
    <AvailableItemName Include="TypeScriptCompile" />
</ItemGroup>

I haven't tested this though.

MarkKharitonov commented 2 years ago

@drewnoakes - The last approach does work. Thank you very much.

MarkKharitonov commented 2 years ago

@drewnoakes - would you like to answer on my SO question, so that I could credit you there?

drewnoakes commented 2 years ago

@MarkKharitonov sure, thanks. Done. I wanted to test my first suggestion on your repro but it seems you deleted the repo. Did it not work for you?

drewnoakes commented 2 years ago

Also, for what you're trying to do, this might be helpful: https://github.com/microsoft/MSBuildSdks/tree/main/src/NoTargets

MarkKharitonov commented 2 years ago

The repo was somehow private. I changed it back to public. Sorry for that.