Is there a .NET Core CLI pre before build task?

前端 未结 1 983
猫巷女王i
猫巷女王i 2020-12-14 03:30

The question

I assume when msbuild is about to compile source code files, it produces a list of files to build, based on Include and

相关标签:
1条回答
  • 2020-12-14 04:02

    The "default items" as the .NET SDK calls it are part of the static evaluation of the project file - before any target is run. So you'll need a target that is run before the @(Compile) items are needed.

    The trick is to include files added to the filesystem after the custom tool is run. This can be done by re-scanning all files and excluding those already part of the project inside a target that is run before the build:

      <Target Name="GenerateSomeFiles" BeforeTargets="BeforeBuild">
        <Exec Command="dotnet my-tool" />
        <ItemGroup>
          <Compile Include="**/*$(DefaultLanguageSourceExtension)"
                   Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);$(BaseIntermediateOutputPath)**;$(BaseOutputPath)**;@(Compile)" />
        </ItemGroup>
      </Target>
    
    0 讨论(0)
提交回复
热议问题