Search code examples
msbuildcsproj

EmbeddedResource not working inside Target


I have some TypescriptCompile files which I then want to embed in my .dll. I had to migrate to the new csproj format and now I can't embed while inside a Target.

This works:

<Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
       <TargetFramework>net472</TargetFramework>
   </PropertyGroup>
   <ItemGroup>
       <EmbeddedResource  Include="testFile.ts" />
   </ItemGroup>
</Project>

While this does not:

<Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
       <TargetFramework>net472</TargetFramework>
   </PropertyGroup>
   <Target Name="AddGeneratedToBuildOutput" BeforeTargets="CoreCompile">
       <ItemGroup>
           <PackageFiles Include="$(MSBuildProjectDirectory)\**\*.*;"/>
       </ItemGroup>
       <Message Text="The target is called: %(PackageFiles.FullPath)" Importance="high"/>
       <ItemGroup>
           <EmbeddedResource  Include="testFile.ts" />          
       </ItemGroup>
    </Target>
</Project>

Note that the message gets written and the referred file is in the project, hence we can be sure that the target gets called.

I already tried other targets instead of CoreCompile but since I'm using TypeScriptCompile, if I use BeforeBuild, Build or ResolveReferences I get compilation errors since the .js files are not generated yet.

I'm using JetBrains' DotPeek to inspect the resources and using msbuild 15.0.


Solution

  • Solution to this problem is here: https://github.com/microsoft/msbuild/issues/4778