-
Notifications
You must be signed in to change notification settings - Fork 564
[One .NET] exclude .dll/.pdb files from @(None) or @(Content) #6514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jonpryor
merged 1 commit into
dotnet:main
from
jonathanpeppers:copytopublishdirectory-items
Nov 30, 2021
Merged
[One .NET] exclude .dll/.pdb files from @(None) or @(Content) #6514
jonpryor
merged 1 commit into
dotnet:main
from
jonathanpeppers:copytopublishdirectory-items
Nov 30, 2021
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
Author
Context: https://github.com/jonathanpeppers/android-pipe/blob/c313259b782bff40204e1a1ca988659dc7d3180b/csharp/Benchmark.csproj#L25 When using BenchmarkDotNet in a .NET 6 Android app for the first time, I hit this build error: Microsoft.Android.Sdk.AssemblyResolution.targets(106,5): error XAPRAS7009: System.InvalidOperationException: PE image does not have metadata. at System.Reflection.PortableExecutable.PEReader.GetMetadataBlock() at System.Reflection.PortableExecutable.PEReader.GetMetadata() at System.Reflection.Metadata.PEReaderExtensions.GetMetadataReader(PEReader peReader, MetadataReaderOptions options, MetadataStringDecoder utf8Decoder) at System.Reflection.Metadata.PEReaderExtensions.GetMetadataReader(PEReader peReader) at Xamarin.Android.Tasks.ProcessAssemblies.DeduplicateAssemblies(List`1 output, Dictionary`2 symbols) at Xamarin.Android.Tasks.ProcessAssemblies.RunTask() at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in C:\src\xamarin-android\external\xamarin-android-tools\src\Microsoft.Android.Build.BaseTasks\AndroidTask.cs:line 17 I could also reproduce the issue in a test. The problem is that `Microsoft.Diagnostics.Tracing.TraceEvent.props` includes Windows native `.dll` files: <None Condition="Exists('$(MSBuildThisFileDirectory)..\lib\native\x86\KernelTraceControl.dll')" Include="$(MSBuildThisFileDirectory)..\lib\native\x86\KernelTraceControl.dll"> <Link>x86\KernelTraceControl.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>False</Visible> </None> <None Condition="Exists('$(MSBuildThisFileDirectory)..\lib\native\x86\KernelTraceControl.Win61.dll')" Include="$(MSBuildThisFileDirectory)..\lib\native\x86\KernelTraceControl.Win61.dll"> <Link>x86\KernelTraceControl.Win61.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>False</Visible> </None> <None Condition="Exists('$(MSBuildThisFileDirectory)..\lib\native\x86\msdia140.dll')" Include="$(MSBuildThisFileDirectory)..\lib\native\x86\msdia140.dll"> <Link>x86\msdia140.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>False</Visible> </None> <None Condition="Exists('$(MSBuildThisFileDirectory)..\lib\native\x86\msvcp140.dll')" Include="$(MSBuildThisFileDirectory)..\lib\native\x86\msvcp140.dll"> <Link>x86\msvcp140.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>False</Visible> </None> <None Condition="Exists('$(MSBuildThisFileDirectory)..\lib\native\x86\vcruntime140.dll')" Include="$(MSBuildThisFileDirectory)..\lib\native\x86\vcruntime140.dll"> <Link>x86\vcruntime140.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>False</Visible> </None> <None Condition="Exists('$(MSBuildThisFileDirectory)..\lib\native\amd64\KernelTraceControl.dll')" Include="$(MSBuildThisFileDirectory)..\lib\native\amd64\KernelTraceControl.dll"> <Link>amd64\KernelTraceControl.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>False</Visible> </None> <None Condition="Exists('$(MSBuildThisFileDirectory)..\lib\native\amd64\msdia140.dll')" Include="$(MSBuildThisFileDirectory)..\lib\native\amd64\msdia140.dll"> <Link>amd64\msdia140.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>False</Visible> </None> <None Condition="Exists('$(MSBuildThisFileDirectory)..\lib\native\amd64\msvcp140.dll')" Include="$(MSBuildThisFileDirectory)..\lib\native\amd64\msvcp140.dll"> <Link>amd64\msvcp140.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>False</Visible> </None> <None Condition="Exists('$(MSBuildThisFileDirectory)..\lib\native\amd64\vcruntime140.dll')" Include="$(MSBuildThisFileDirectory)..\lib\native\amd64\vcruntime140.dll"> <Link>amd64\vcruntime140.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>False</Visible> </None> <None Condition="Exists('$(MSBuildThisFileDirectory)..\lib\native\amd64\vcruntime140_1.dll')" Include="$(MSBuildThisFileDirectory)..\lib\native\amd64\vcruntime140_1.dll"> <Link>amd64\vcruntime140_1.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>False</Visible> </None> This isn't great... We don't really want users to be able to use `@(None)` to include random `.dll` files... I could workaround the problem by using this in the `.csproj`: <None Remove="@(None->WithMetadataValue('Extension', '.dll'))" /> Reviewing the `.binlog`, I found the only way to identify `%(CopyToOutputDirectory)` items was to do: <ResolvedFileToPublish Remove="@(_SourceItemsToCopyToPublishDirectory)" /> Even though `@(_SourceItemsToCopyToPublishDirectory)` has a private name, it seems like the only way to fix this? If it was ever renamed, we have a test and the above code would change to a no-op. The test now passes, excluding these files from the build.
3960ae7 to
82ce550
Compare
dellis1972
approved these changes
Nov 30, 2021
jonathanpeppers
added a commit
that referenced
this pull request
Nov 30, 2021
Context: https://github.com/jonathanpeppers/android-pipe/blob/c313259b782bff40204e1a1ca988659dc7d3180b/csharp/Benchmark.csproj#L25 When using BenchmarkDotNet in a .NET 6 Android app for the first time, I hit this build error: Microsoft.Android.Sdk.AssemblyResolution.targets(106,5): error XAPRAS7009: System.InvalidOperationException: PE image does not have metadata. at System.Reflection.PortableExecutable.PEReader.GetMetadataBlock() at System.Reflection.PortableExecutable.PEReader.GetMetadata() at System.Reflection.Metadata.PEReaderExtensions.GetMetadataReader(PEReader peReader, MetadataReaderOptions options, MetadataStringDecoder utf8Decoder) at System.Reflection.Metadata.PEReaderExtensions.GetMetadataReader(PEReader peReader) at Xamarin.Android.Tasks.ProcessAssemblies.DeduplicateAssemblies(List`1 output, Dictionary`2 symbols) at Xamarin.Android.Tasks.ProcessAssemblies.RunTask() at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in C:\src\xamarin-android\external\xamarin-android-tools\src\Microsoft.Android.Build.BaseTasks\AndroidTask.cs:line 17 I could also reproduce the issue in a test. The problem is that `Microsoft.Diagnostics.Tracing.TraceEvent.props` includes Windows native `.dll` files: <None Condition="Exists('$(MSBuildThisFileDirectory)..\lib\native\x86\KernelTraceControl.dll')" Include="$(MSBuildThisFileDirectory)..\lib\native\x86\KernelTraceControl.dll"> <Link>x86\KernelTraceControl.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>False</Visible> </None> <None Condition="Exists('$(MSBuildThisFileDirectory)..\lib\native\x86\KernelTraceControl.Win61.dll')" Include="$(MSBuildThisFileDirectory)..\lib\native\x86\KernelTraceControl.Win61.dll"> <Link>x86\KernelTraceControl.Win61.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>False</Visible> </None> <None Condition="Exists('$(MSBuildThisFileDirectory)..\lib\native\x86\msdia140.dll')" Include="$(MSBuildThisFileDirectory)..\lib\native\x86\msdia140.dll"> <Link>x86\msdia140.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>False</Visible> </None> <None Condition="Exists('$(MSBuildThisFileDirectory)..\lib\native\x86\msvcp140.dll')" Include="$(MSBuildThisFileDirectory)..\lib\native\x86\msvcp140.dll"> <Link>x86\msvcp140.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>False</Visible> </None> <None Condition="Exists('$(MSBuildThisFileDirectory)..\lib\native\x86\vcruntime140.dll')" Include="$(MSBuildThisFileDirectory)..\lib\native\x86\vcruntime140.dll"> <Link>x86\vcruntime140.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>False</Visible> </None> <None Condition="Exists('$(MSBuildThisFileDirectory)..\lib\native\amd64\KernelTraceControl.dll')" Include="$(MSBuildThisFileDirectory)..\lib\native\amd64\KernelTraceControl.dll"> <Link>amd64\KernelTraceControl.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>False</Visible> </None> <None Condition="Exists('$(MSBuildThisFileDirectory)..\lib\native\amd64\msdia140.dll')" Include="$(MSBuildThisFileDirectory)..\lib\native\amd64\msdia140.dll"> <Link>amd64\msdia140.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>False</Visible> </None> <None Condition="Exists('$(MSBuildThisFileDirectory)..\lib\native\amd64\msvcp140.dll')" Include="$(MSBuildThisFileDirectory)..\lib\native\amd64\msvcp140.dll"> <Link>amd64\msvcp140.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>False</Visible> </None> <None Condition="Exists('$(MSBuildThisFileDirectory)..\lib\native\amd64\vcruntime140.dll')" Include="$(MSBuildThisFileDirectory)..\lib\native\amd64\vcruntime140.dll"> <Link>amd64\vcruntime140.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>False</Visible> </None> <None Condition="Exists('$(MSBuildThisFileDirectory)..\lib\native\amd64\vcruntime140_1.dll')" Include="$(MSBuildThisFileDirectory)..\lib\native\amd64\vcruntime140_1.dll"> <Link>amd64\vcruntime140_1.dll</Link> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <Visible>False</Visible> </None> This isn't great; we don't really want users to be able to use `@(None)` to include random `.dll` files… I could workaround the problem by using this in the `.csproj`: <None Remove="@(None->WithMetadataValue('Extension', '.dll'))" /> Reviewing the `.binlog`, I found the only way to identify `%(CopyToOutputDirectory)` items was to do: <ResolvedFileToPublish Remove="@(_SourceItemsToCopyToPublishDirectory)" /> Even though `@(_SourceItemsToCopyToPublishDirectory)` has a private name, it seems like the only way to fix this? If it was ever renamed, we have a test and the above code would change to a no-op. The test now passes, excluding these files from the build.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Context: https://github.com/jonathanpeppers/android-pipe/blob/c313259b782bff40204e1a1ca988659dc7d3180b/csharp/Benchmark.csproj#L25
When using BenchmarkDotNet in a .NET 6 Android app for the first time,
I hit this build error:
I could also reproduce the issue in a test.
The problem is that
Microsoft.Diagnostics.Tracing.TraceEvent.propsincludes Windows native
.dllfiles:This isn't great... We don't really want users to be able to use
@(None)to include random.dllfiles...I could workaround the problem by using this in the
.csproj:Reviewing the
.binlog, I found the only way to identify%(CopyToOutputDirectory)items was to do:Even though
@(_SourceItemsToCopyToPublishDirectory)has a privatename, it seems like the only way to fix this? If it was ever renamed,
we have a test and the above code would change to a no-op.
The test now passes, excluding these files from the build.