SyndRain
SyndRain

Reputation: 3793

Visual Studio Publish generates less files than Build (.NET Framework)

I am publishing a .NET Framework site, using the Visual Studio Publish feature (either to Folder or to IIS).

I noticed some files are not generated/copied by Publish compared to Release Build. For example, Content/*.css files are not generated, which break the published website's styling. Some of my .cs Class files are missing also but somehow did not cause any problem.

What does Publish actually do? Does it do something more than copying the files generated by Build?


Edit: This is my settings for Publish to Folder

<Project>
  <PropertyGroup>
    <DeleteExistingFiles>false</DeleteExistingFiles>
    <ExcludeApp_Data>false</ExcludeApp_Data>
    <LaunchSiteAfterPublish>true</LaunchSiteAfterPublish>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <PublishProvider>FileSystem</PublishProvider>
    <PublishUrl>bin\app.publish\</PublishUrl>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <_TargetId>Folder</_TargetId>
  </PropertyGroup>
</Project>

Note: I'm using Visual Studio 2022

Probably Related: The difference between build and publish in VS? mentions Publish generates the same files.

Upvotes: 1

Views: 377

Answers (1)

SyndRain
SyndRain

Reputation: 3793

Turns out when publishing, files that are excluded from project will not be copied to the output folder (which makes sense). In the original folder those excluded files can still be included by <scripts> or <include> (or in a .config file in my case.) However, they can't be found anymore in the published folder, causing potential harms.

This tells us to be careful when using the Exclude from project feature...

Related: What exactly does 'Include In Project' and 'Exclude From Project' mean in Visual Studio?

Upvotes: 1

Related Questions