Using Pre and Post build actions in dotnet core csproj files

Viewed 9043

I am a .NET Core novice and I am trying to set up a pre-build action in my csproj file. According to [1], we can use Target element to specify a pre-build step as follows:

<Target Name="MyPreCompileTarget" BeforeTargets="Build">
        <Exec Command="generateCode.cmd"/>
</Target>

However, this element does not seem to be picked up by the MSBuild tool. My complete csproj file is given below:

<Project Sdk="Microsoft.NET.Sdk.Web">

    <PropertyGroup>
        <TargetFramework>netcoreapp1.1</TargetFramework>
    </PropertyGroup>

    <ItemGroup>
        <Folder Include="wwwroot\"/>
    </ItemGroup>
    

    <Target Name="MyPreCompileTarget" BeforeTargets="Build">
        <Exec Command="echo meow meow"/>
    </Target>

    <ItemGroup>
        <PackageReference Include="FluentValidation.AspNetCore" Version="7.0.0"/>
        <PackageReference Include="Microsoft.AspNetCore" Version="1.1.2"/>
        <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3"/>
        <PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="1.0.3"/>
        <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2"/>
    </ItemGroup>

    <ItemGroup>
        <ProjectReference Include="..\my-lib\<my-lib>.csproj"/>
    </ItemGroup>

</Project>

References

[1] - https://docs.microsoft.com/en-us/dotnet/articles/core/tools/project-json-to-csproj#the-csproj-format

1 Answers
Related