ASP.NET Core: Exclude or include files on publish

前端 未结 9 798

There were before aspdotnet1.0 include/exclude sections on project.json file

{
  \"exclude\": [
    \"node_modules\",
    \"bower_c         


        
相关标签:
9条回答
  • 2020-11-27 05:03

    In .csproj for Visual Studio versions 15.3 and higher, this keeps the files visible in Visual Studio (whereas "Content Remove" does not), and prevents the files from being published.

    <ItemGroup>
        <Content Update="appsettings*.json" CopyToPublishDirectory="Never" />
    </ItemGroup>
    
    0 讨论(0)
  • 2020-11-27 05:04

    I noticed that my folders with a few files in them were not being published- I tried right clicking the folders in the project to see if I could select an option to include the folder with the deployment- it's not there, but I did find if I select the files inside the folder and mark them to copy on deployment, it will copy the files and create their folder in the process.

    This helps if your folder has files, but doesn't help if your folders are empty.

    0 讨论(0)
  • 2020-11-27 05:05

    With Visual Studio 2017 (tested in 15.6.5), you can right-click on the file in the Solution Explorer and set the Build Action to None.

    It will update your .csproj file like this:

    <ItemGroup>
      <Content Remove="appsettings.Development.json" />
      <Content Remove="appsettings.json" />
      <Content Remove="npm-shrinkwrap.json" />
      <Content Remove="package.json" />
      <Content Remove="tsconfig.json" />
    </ItemGroup>
    
    <ItemGroup>
      <None Include="appsettings.Development.json" />
      <None Include="appsettings.json" />
      <None Include="npm-shrinkwrap.json" />
      <None Include="package.json" />
      <None Include="tsconfig.json" />
    </ItemGroup>
    

    Hope this helps.

    0 讨论(0)
  • 2020-11-27 05:09

    In Visual Studio 2019,

    1. Right-click the file -> Properties
    2. Copy To Output Directory-> Copy always

    1. Save the solution and try publish
    0 讨论(0)
  • From documentation: if you wish to specify, for example, some files to get published with your app, you can still use the known mechanisms in csproj for that (for example, the <Content> element).

    There is a CopyToPublishDirectory attribute for ItemGroup elements that determines whether to copy the file to the publish directory and can have one of the following value:

    • Always,
    • PreserveNewest
    • Never

    Note, that there is also similar CopyToOutputDirectory attribute for output folder.

    Example (from here):

    <ItemGroup>
    
      <None Include="notes.txt" CopyToOutputDirectory="Always" />
      <!-- CopyToOutputDirectory = { Always, PreserveNewest, Never } -->
    
      <Content Include="files\**\*" CopyToPublishDirectory="PreserveNewest" />
      <None Include="publishnotes.txt" CopyToPublishDirectory="Always" />
      <!-- CopyToPublishDirectory = { Always, PreserveNewest, Never } -->
    </ItemGroup>
    

    If you are interesting how project.json -.csproj migration use CopyToPublishDirectory attribute to migrate publish options, you may look into MigratePublishOptionsRule class in dotnet cli repo.

    0 讨论(0)
  • 2020-11-27 05:18

    Edit the .csproj file to manually exclude files/folder from being published.

    You can also refer this

    For web deployment see https://blogs.msdn.microsoft.com/webdev/2010/04/22/web-deployment-excluding-files-and-folders-via-the-web-applications-project-file/.

    project.json has been now replaced by csproj. You can read about it more on https://www.stevejgordon.co.uk/project-json-replaced-by-csproj.

    For Upgrading Existing .NET Core 1.0 Projects or for using Using .NET Core 1.1 you can read https://blogs.msdn.microsoft.com/dotnet/2016/11/16/announcing-net-core-1-1/.

    0 讨论(0)
提交回复
热议问题