C# - 在csproj文件中添加通配符和添加新文件

Mau*_*tti 9 c# csproj visual-studio

.csproj文件中,Visual Studio和Xamarin Studio默认保留对项目内使用的每个文件的引用.

<ItemGroup>
    <Compile Include="Utils\Foo1Utils.cs" />
    <Compile Include="Utils\Foo2Utils.cs" />
    <Compile Include="Services\FooService.cs" />
    ...
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)

为了避免在每次添加文件时我们的解决方案中的csproj文件发生冲突,我们开始使用通配符:

<ItemGroup>
    <Compile Include="Utils\*.cs" />
    <Compile Include="Services\*.cs" />
    ...
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)

问题是,似乎都在Visual Studio和Xamarin Studio是不可能的"解释"对我们使用通配符的IDE,当我们添加一个新的文件到项目中,他们添加一个新的参考文件忽略通配符*.cs上文件夹.它仍然是一个很好的解决方案,因为我们不需要在每次添加文件时都提交.csproj,但现在我们必须每次都重置它们......任何人都知道是否有解决方案?

编辑:与Rider(JetBrains)没有这个问题,如果在csproj中有一个通配符,我添加一个新文件一切正常.

小智 3

如果您对项目使用新格式 ( .net core 2 ),它将使用通配符包含,而无需为项目文件夹中的文件指定它。您可以手动设置目标框架,以便仍然编译到您想要的任何目标。