I got an assembly containing only static classes with constants
public static class C {
public const int Value = 123;
}
I use this assembly in different applications and it is marked with CopyLocal = false
and is not deployed.
This work for netframework
applications but for netcoreapp
I get an error message saying the assembly can not be found.
The assembly is not referenced in the compiled code (verified with ildasm
) but there is still a reference in the .deps.json
file.
Do I need to deploy the assembly with core applications or is there a settings to exclude it from the .deps.json
file?
(Most of my netframework applications are only small executables so it seemed unnecessary to include a multi-megabyte, not used, assembly in the deploy. Core application are large and multi-file from start so it doesn't matter)
Edit: found the problem.
The assembly didn't actually have CopyLocal = false
. It used a .targets file to remove it at build time
<Target Name="PreventConstantsCopyLocal" AfterTargets="ResolveReferences">
<ItemGroup>
<ReferenceCopyLocalPaths Remove="@(ReferenceCopyLocalPaths)"
Condition="'%(ReferenceCopyLocalPaths.NuGetPackageId)' == 'MyConstants'" />
</ItemGroup>
</Target>
I just added a an extra condition
And ('%(MSBuildRuntimeType)' == '' Or '%(MSBuildRuntimeType)' == 'Full')
so the constants are copied to output in core builds.