Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
385 views
in Technique[技术] by (71.8m points)

c# - Add SQLite dtabase file from a class library to ASP.NET Core MVC output directory on project build

I created a class library project and put my SQLite database in it, and set these lines in the .csproj file:

<ItemGroup>
    <Content Include="DataDataBaselocations.db">
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
</ItemGroup>

If I locally reference that class library to my main project (ASP.NET Core), it works fine and on every build it will copy the database file to this directory:

***inDebug
et5.0DataDataBase

But when I publish the class library to NuGet, and install it in my main project, it doesn't copy the file.

Any help why this is happening and what should I do?

This is my package in NuGet package explorer

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just find out the answer

  <ItemGroup>
    <Content Include="DataDataBaselocations.db">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <PackageCopyToOutput>true</PackageCopyToOutput>
    </Content>
  </ItemGroup>

This line will do the job

<PackageCopyToOutput>true</PackageCopyToOutput>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...