Reputation: 7207
I have this code snippet in my .csproj
file to force a specific version of System.Runtime.CompilerServices.Unsafe.dll
to be copied into the output folder, after build:
<Target Name="ForcingUnsafeSpecificVersion" AfterTargets="AfterBuild">
<Copy SourceFiles="Path\System.Runtime.CompilerServices.Unsafe.dll" DestinationFolder="$(OutDir)" />
</Target>
But it doesn't work. It doesn't override the version of the output directory, or probably something else is overriding it.
I also tried:
<ItemGroup>
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.6.0-preview.18571.3">
<NoWarn>NU1605</NoWarn>
</PackageReference>
</ItemGroup>
Still no success. I also tried:
<ItemGroup>
<None Include="Path\System.Runtime.CompilerServices.Unsafe.dll">
<Link>System.Runtime.CompilerServices.Unsafe.dll</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
Didn't work. Please note that this line works
<ItemGroup>
<None Include="Path\System.Runtime.CompilerServices.Unsafe.dll">
<Link>System.Runtime.CompilerServices.Unsafe2.dll</Link>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
If I add number 2 at the end of the name of the output file, then it works. But it seems that all of these build configurations fail and get overridden by something else.
How do I force this file to be copied into the output directory?
Upvotes: 1
Views: 519
Reputation: 28126
1.It seems you're simply trying to copy something to OutDir after build.
<Target Name="ForcingUnsafeSpecificVersion" AfterTargets="AfterBuild">
<Copy SourceFiles="Path\System.Runtime.CompilerServices.Unsafe.dll" DestinationFolder="$(OutDir)" />
</Target>
This task should always work if you just need to copy one file,if not, maybe it could be something about access. You can add a OverwriteReadOnlyFiles
options to the command to check if it helps:
<Target Name="ForcingUnsafeSpecificVersion" AfterTargets="AfterBuild">
<Copy SourceFiles="Path\System.Runtime.CompilerServices.Unsafe.dll" DestinationFolder="$(OutDir)" OverwriteReadOnlyFiles="true"/>
</Target>
2.If it still fails, change the msbuild verbosity to Detailed
and check the detailed log in Output window:
You can figure out what happened in that process according to that log.
3.Also, you can try if you can copy one assembly to target path by copy or xcopy command in cmd.exe
, if it works, then you can also consider using a Exec Task to do what you want.
4.If all above not helps, please share more details of your project type and the details about the content of the rpoject(nuget packages...). I guess if there's any misunderstanding about the $(OutDir)
, maybe actually you're trying to copy that to publish/deploy
folder instead of normal output folder(bin\Debug\netcoreappx.x...).
Upvotes: 1