I recently migrated our build platform from an ancient one build on top of rake (don't ask, seriously) to one using msbuild. Because many of our team members don't use Visual Studio (again, don't ask), they are used to being able to drop in a .cs file into the project folder, and just having it magically appear as part of the build.
As such, the .csproj file for this project includes the following line:
<ItemGroup>
<Compile Include="**\*.cs" Exclude="obj" />
</ItemGroup>
This works great when compiling via msbuild directly. However, when I open the project in Visual Studio, it decides to "helpfully" expand the wildcard into a full list of files, seemingly as soon as I open it:
<ItemGroup>
<Compile Include="Controller.cs" />
<Compile Include="MyClass.cs" />
<Compile Include="MyClass2.cs" />
<Compile Include="etc/etc/Something.cs" />
<!-- and so forth -->
</ItemGroup>
While technically this still works, it also causes grief because it removes the wildcard ability.
I tried implementing a technique shown on this page, but I couldn't get it to work with simple compilation.
Has anyone had this problem before? Is there any way to work around this?
EDIT: To clarify what I mean by "couldn't get it to work", this is what I did:
In Main.csproj, I have this:
<!-- References in here -->
</ItemGroup>
<Import Project="Imports.proj" />
<ItemGroup>
<!-- ProjectReferences down here -->
Then, I created Imports.proj, with this:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Compile Include="**\*.cs" Exclude="obj" />
</ItemGroup>
</Project>
When I open Main.csproj in Visual Studio, it doesn't show any files. It could be that the <Import>
line is wrong?
Edit 2: Interestingly, it still builds through Visual Studio, it just doesn't show the files as part of the project.
<Compile Include="**\*.cs" Exclude="obj" />
. What exactly did you try? Are you sure you put the import at the correct place? – Alonaalone