8

I have an asp.net web application project that I am publishing via Build > Publish within visual studio 2013. I am publishing to the file system, using the precompile option selected. My project has "Only files needed to run this application" selected in the Package/Publish Web settings screen. However, regardless of what I do, the .cs files (code-behind) and designer.cs files get copied to the output folder during publishing.

This project was created by using the File > New Project > ASP.NET Web Application functionality in visual studio. Then files from a website project were added to the application, and the "convert to web application" command was run on it from the build menu. The conversion to a web app seems to have worked fine, but I am unable to publish without the .cs files being included.

What else needs to be done in order to get a web application to publish without the code-behind files included? Any ideas on what I can look into?

Could there be a setting at the solution level that is causing this? The new web application was added to a pre-existing solution with about a dozen other projects.

Another thing to note is that when I create a new web app with visual studio in a new project, and publish w/ the same settings, it does NOT include the .cs files.

I've also tried deleting and then creating a new publish profile.

Rafe
  • 8,467
  • 8
  • 47
  • 67
  • Click one of the .cs files, then look in the Property grid (F4) to see what the "Build action" is set to for the .cs file. – John Saunders May 15 '14 at 19:25
  • @JohnSaunders Build Action = Compile. – Rafe May 15 '14 at 19:27
  • Hmmm.. Not what I expected. Is there a post-build step? – John Saunders May 15 '14 at 19:28
  • @JohnSaunders No, no post-build. – Rafe May 15 '14 at 19:30
  • In my case all files, regardless of whether they are marked as compile or not, get published to the destination folder. This is with the same settings as shown above. If I create a new project file and add all of the same stuff to it, it publishes as expected. However this is a work around rather than a fix as it took a long time to get all the references etc right should it happen again... – Ed Bishop Sep 08 '14 at 14:53
  • I don't suppose you came up with fix? – BenCr Sep 16 '14 at 09:19

2 Answers2

5

I just fixed this by deleting my old publish profile and creating a new one.

The new one appeared to have all the same settings as the old one but when I published it didn't copy the .cs files.

Edit: This answer is a lie. There was a difference between the two profiles. The new profile was in Release configuration.

Edit 2: There's a setting in the project settings which determines what gets published. Select "only files needed to run this application" from the following page.

Publish Settings Page

BenCr
  • 5,991
  • 5
  • 44
  • 68
2

Turns out that I added this line to my csproj file earlier when I was trying to get my project to build on our build server. Removing it fixed the problem:

<Target Name="GatherAllFilesToPublish"></Target>
Rafe
  • 8,467
  • 8
  • 47
  • 67