Visual Studio publish to folder is publishing all folders even the .vs folder

Salik Rafiq 1 Reputation point

I have a old framework application that I've been tasked with fixing. It's been coded by an over-seas company and it's been brought in-house for the small customer requests for customisations it gets.

It's pretty badly written. Anyway, when I use the publish to folder the result is all the files and folders are published including the .vs folder. All the .cs files are published, the packages folder and it's contents are published. I've marked many files with 'none' on the build action and 'do not copy' and these are also published. Even the pubxml files are published.

Ive never seen this before on a application nor even on a website.

 I have check the csproj file and can't see anything obvious. I have set the "only files necessary.." option on web publish.  

Anyone have any ideas what's causing this. Any tips welcome.

A set of technologies in the .NET Framework for building web applications and XML web services.
3,407 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 28,831 Reputation points Microsoft Vendor

    Hi @Salik Rafiq ,
    Are the files you mentioned included in the solution directory?
    I think what you set should be "Copy to output directory", "Copy to output directory" is a property of a file in a Visual Studio project that defines whether the file will be copied as-is to the project's build path. Treating files as-is allows us to use relative paths to files within the project.
    If you don't want to publish some files, you need to set <CopyToPublishDirectory> in csproj file.
    You can also right-click a folder > Exclude from Project. Then delete the old publish profile and create a new publish profile for publishing.
    When you publish your website, Visual Studio compiles all your cs/vb/class code into binaries (dll). This dll file can be found in your site bin folder.
    Do you build your project before publishing?

    You can also choose to publish only a single file according to your needs, and you can view the document for specific steps.
    Best regards,
    Lan Huang

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.