Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excluding folder contents from publish #7861

Closed
ralphking opened this issue Mar 6, 2017 · 20 comments
Closed

Excluding folder contents from publish #7861

ralphking opened this issue Mar 6, 2017 · 20 comments

Comments

@ralphking
Copy link

Publishing from Visual studio to IIS server on Windows Server 2012 R2

In .csproj:

<ItemGroup>
   <Content Include="wwwroot\LicenceFiles" CopyToPublishDirectory="Never" />
</ItemGroup>

Expected behavior

For the contents of this directory not to be published

Actual behavior

The directory contents are being added to the server when publishing

Is there another way in core to stop folders from being published? Specifically, this is a folder that I am writing generated PDF files to. Obviously I don't want to be pushing up any of the files that have been generated in development, so want to retain the folder on the server but just not sync any content.

@livarcocc
Copy link
Contributor

Please use

<ItemGroup>
   <Content Update="wwwroot\LicenceFiles" CopyToPublishDirectory="Never" />
</ItemGroup>

The Web SDK (assuming that's what you are using) is including these files for you already. So you need to update the files' metadata to prevent them from being published.

@ralphking
Copy link
Author

Unfortunately that is giving the same behaviour

@livarcocc
Copy link
Contributor

@mlorbetske Can you take a look at this?

Also, how are you publishing this? CLI, VS? Which version?

@ralphking
Copy link
Author

This is in VS 2017 RC, Core 1.1.

If I right click a folder and exclude a file from the project, I can see that in .csproj it will have automatically added an itemgroup to remove the file, and that will work. It only seems to be what I am adding that isn't working with regards to changes to .csproj

@livarcocc
Copy link
Contributor

livarcocc commented Mar 7, 2017

Oh, wwwroot\LicenceFiles is a folder? you need to do wwwroot\LicenseFiles\**\* if you want to update the metadata for everything under that folder.

@ralphking
Copy link
Author

Is that kind of thing covered in the docs anywhere?

Ie CopyToPublishDirectory, CopyToOutputDirectory and other options

@livarcocc
Copy link
Contributor

@blackdwarf @mairaw for documentation.

@ralphking barring additional documentation, is this working for you know? Can we go ahead and close this issue?

@ralphking
Copy link
Author

No, it doesn't work. There's not much more information that I can give to debug unfortunately.

Is there any documentation for it at all at the moment?

Thanks

@mlorbetske
Copy link
Contributor

Cc @vijayrkn

@vijayrkn
Copy link
Contributor

@ralphking
I just tried this on VS 2017 RTW and seems to be working. It is excluding all the files (including sub directories) from wwwroot\images

  <ItemGroup>
    <Content Update="wwwroot\images\**\*.*" CopyToPublishDirectory="Never" />
  </ItemGroup>

If you are publishing from VS, please make sure to check this so that if the files are already present, they will be removed as well.

image

@livarcocc
Copy link
Contributor

I updated my previous comment above about which glob to use. I didn't realize that github that processed it to appear different from what I had typed.

Also, follow up @vijayrkn instructions above and let us know if that works out for you.

@livarcocc
Copy link
Contributor

@ralphking I am closing this issue. If this is still not working for you, please re-activate.

@mairaw
Copy link
Contributor

mairaw commented Mar 15, 2017

I was trying to see if the MSBuild reference had those options but it doesn't seem to have all of them:
https://docs.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-items.

I'll open an issue in their repo for this.

/cc @kempb

@max-favilli
Copy link

I have the same problem and tried with:

  <ItemGroup>
    <Content Update="wwwroot\images\**\*.*" CopyToPublishDirectory="Never" />
  </ItemGroup>

But it doesn't work, it's still publishing wwwroot\images and all it's content

@vijayrkn
Copy link
Contributor

@max-favilli - Can you please share a repro project?

If you are publishing from VS, existing files are not deleted by default. You can check the option to 'Delete additional files' in the settings dialog.

@msftgits msftgits transferred this issue from dotnet/cli Jan 31, 2020
@metoule
Copy link

metoule commented Mar 31, 2020

FYI this doesn't work if you want to exclude items from a Razor Class Library.

@mmedi005
Copy link

I'm also having this problem as well. Any ideas?

@letscodego
Copy link

letscodego commented May 21, 2020

this blog post help me to fix this issue for my publish.
By <ExcludeFoldersFromDeployment>Folder1;Folder2</ExcludeFoldersFromDeployment>
I could exclude some folders.

@mmedi005
Copy link

mmedi005 commented May 21, 2020 via email

@mmedi005
Copy link

I've tried so many ways to exclude a folder and can't get it to work. Has anyone have documentation on this that is with the recent vs and asp core 3?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants