Reputation: 3
I have noticed a minor difference in behavior between Visual Studio 2017 and Visual Studio 2019. When I open a solution with VS 2017 it will automatically create folders that are mentioned in the project files (e.g. <Folder Include="Data\">
in a .csproj
file). Visual Studio 2019 won't do that though. Is there a way to change this behavior in Visual Studio 2019 so that it too creates those folders if they don't exist?
EDIT: I first noticed this problem in combination with TFVC. When other people add empty folders to their solution it gets added to the .csproj file but when checking it in the empty folder is ignored. When I get that project from TFVC and open it with VS 2017 the folders are automatically created but not with VS 2019.
I would like these folders to be created since the person checking them in expected them to be there. TFVC can't work with empty folders, so it seemed good to me that VS 2017 solved the problem. Unfortunately VS 2019 seems to behave slightly differently.
To reproduce:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>81fa1651-0a21-4ed6-8626-763141ab67cf</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TestDotNetFramework</RootNamespace>
<AssemblyName>TestDotNetFramework</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System"/>
<Reference Include="System.Core"/>
<Reference Include="System.Xml.Linq"/>
<Reference Include="System.Data.DataSetExtensions"/>
<Reference Include="Microsoft.CSharp"/>
<Reference Include="System.Data"/>
<Reference Include="System.Net.Http"/>
<Reference Include="System.Xml"/>
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<!-- I added these manually -->
<ItemGroup>
<Folder Include="TestFolder\" />
<Folder Include="TestFolder2\Testing\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Upvotes: 0
Views: 2941
Reputation: 23808
I also faced the situation in my side. And it seems that only net framework projects on VS2017 could realize this. And net core projects, also, net framework on VS2019 cannot create the real folder by Folder Include
from csproj
file.
I cannot explain it so that I have reported it to our DC Forum. You can vote it or add any comments if I did not describe the issue in detail.
Since the ticket might take a long time, as a workaround, you could use these on the csproj
file of VS2019:
<ItemGroup>
<Folder Include="TestFolder"/>
</ItemGroup>
<Target Name="CreateAppDataFolder" BeforeTargets="PrepareForBuild">
<MakeDir Directories="$(ProjectDir)TestFolder" />
</Target>
Upvotes: 2
Reputation: 311195
I think you might be mistaken. In VS2017, if I create a new .NET Core Console Application project then edit the project file to contain:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="NonExistent" />
</ItemGroup>
</Project>
Then Solution Explorer shows:
And Windows Explorer shows:
This is the same behaviour in VS2019.
Upvotes: 0