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

Salik Rafiq 1 Reputation point
2022-11-25T10:49:53.023+00:00

I have a old asp.net 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 asp.net 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.

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

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 30,176 Reputation points Microsoft Vendor
    2022-11-28T08:28:57.973+00:00

    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.
    https://learn.microsoft.com/en-us/answers/questions/172352/how-can-i-include-different-files-when-publishing.html
    You can also right-click a folder > Exclude from Project. Then delete the old publish profile and create a new publish profile for publishing.
    264694-image.png
    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.
    https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file/overview?tabs=vs#publish-a-single-file-app
    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.