-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Describe the bug
When using <ProjectReference>
with <ExcludeAssets>contentFiles</ExcludeAssets>
, content files (items with <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
) from the referenced project are still being copied to the output directory of the referencing project. This behavior is observed with .NET SDK 9.0.200 (dotnet --version).
The ExcludeAssets="contentFiles"
metadata is recognized by MSBuild on the resolved project reference item during the build of the referencing project. However, the content files from the referenced project still appear in internal MSBuild item lists (such as _TransitiveItemsToCopyToOutputDirectory
) and are subsequently copied to the output.
To Reproduce
-
Set up a minimal reproduction:
A minimal reproduction repository can be found at: [repository]- Alternatively, follow these manual steps:
-
Create a new directory for the test (e.g.,
ExcludeAssetsRepro
). -
Inside
ExcludeAssetsRepro
, create a class library project (e.g.,ReferencedLib
):- Command:
dotnet new classlib -o ReferencedLib -f net8.0
- Replace
ReferencedLib\ReferencedLib.csproj
with:<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> </PropertyGroup> <ItemGroup> <Content Include="MyScript.sql"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </Content> </ItemGroup> </Project>
- Create an empty file named
MyScript.sql
in theReferencedLib
directory.
- Command:
-
Inside
ExcludeAssetsRepro
, create a console application project (e.g.,MainApp
) that references the class library:- Command:
dotnet new console -o MainApp -f net8.0
- Replace
MainApp\MainApp.csproj
with:<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net8.0</TargetFramework> </PropertyGroup> <ItemGroup> <ProjectReference Include="..\ReferencedLib\ReferencedLib.csproj"> <ExcludeAssets>contentFiles</ExcludeAssets> </ProjectReference> </ItemGroup> </Project>
- Command:
-
Build the
MainApp
project:- Navigate to the
MainApp
directory:cd MainApp
- Build the project:
dotnet build
- Navigate to the
Expected behavior:
The file MyScript.sql
should NOT be present in the output directory of MainApp
(e.g., MainApp\bin\Debug\net8.0\
).
Actual behavior:
The file MyScript.sql
IS present in the output directory of MainApp
(e.g., MainApp\bin\Debug\net8.0\MyScript.sql
).
Exceptions (if any)
None. The build succeeds without errors, but the output content is incorrect.
Further technical details
dotnet --info
output: