Copy files to output directory using csproj dotnetcore

前端 未结 7 1680
猫巷女王i
猫巷女王i 2020-11-29 20:54

So my issue is pretty simple. I have some files that I want to be copied to the build output directory whether it is a debug build or a release publish. All of the informati

相关标签:
7条回答
  • 2020-11-29 21:33

    Thanks you save my day, if you need to force copy of a specific nuget package into an asp.net core project (2.2), add at the end of your csproj :

    <!-- Force copy MathNet because we need it in compilation -->
    <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="Build">
        <PropertyGroup>
            <ErrorText>This project references NuGet package(s) that are missing on this computer. The missing file is {0}.</ErrorText>
        </PropertyGroup>
        <Error Condition="!Exists('..\packages\MathNet.Numerics.4.8.1\lib\netstandard2.0\MathNet.Numerics.dll')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MathNet.Numerics.4.8.1\lib\netstandard2.0\MathNet.Numerics.dll'))" />
    </Target>
    
    <ItemGroup>
        <ContentWithTargetPath Include="..\packages\MathNet.Numerics.4.8.1\lib\netstandard2.0\MathNet.Numerics.dll">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
           <TargetPath>MathNet.Numerics.dll</TargetPath>
        </ContentWithTargetPath>
    </ItemGroup>
    
    0 讨论(0)
提交回复
热议问题