开发者

Can MS Build include all Library project code files without specifying them individually, and play well with Visual Studio?

Is there a way to instruct MS Build through the regular .csproj file of a class library project to include all code files (i.e. all .cs files in the project tree, sub-folders included) without listing them individually?

The closest solution I'm able to find is Using Wildcards to Specify Items.

This is an example of how Visu开发者_开发百科al studio builds the instruction on a file-by-file basis in my class library project:

  <ItemGroup>
    <Compile Include="Controllers\HomeController.cs" />
    <Compile Include="Controllers\ParticipantController.cs" />
    <Compile Include="Global.asax.cs">
      <DependentUpon>Global.asax</DependentUpon>
    </Compile>
    <Compile Include="Models\ParticipantModel.cs" />
    <Compile Include="Models\UserModel.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="Utility.cs" />
  </ItemGroup>

A different kind of project, Website projects, use a mechanism whereby file modifications are detected and those files recompiled. The concept of compiling everything relevant is what I'm going for with a class library project but without the need for detection of changes.

The related Visual Studio "issue":

I realize my ideal solution isn't likely adhered to by Visual Studio - which builds out the build file one file at a time - so I would end up manually editing the build file. Is there a way to make Visual Studio play nicely with my ideal solution?


Try including an external MSBuild file, that includes every file:

File: IncludeEverything.proj

  <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="BeforeBuild">
      <ItemGroup>
        <Compile Remove="@(Compile)" />
        <Compile Include="*.cs;.\**\*.cs" />
      </ItemGroup>
    </Target>
  </Project>

Change your csproj, to import the other:

  ...
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <Import Project="IncludeEverything.proj" />
  ...

By using this solution, it does not matter whether VS includes files in csproj or not... at the end, everything will be included.

This makes this solution easy to reuse in other projects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜