Web Application won't publish without .cs files
Asked Answered
I

2

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.

Ise answered 15/5, 2014 at 19:22 Comment(6)
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.Appoggiatura
@JohnSaunders Build Action = Compile.Ise
Hmmm.. Not what I expected. Is there a post-build step?Appoggiatura
@JohnSaunders No, no post-build.Ise
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...Curmudgeon
I don't suppose you came up with fix?Salmonella
S
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

Salmonella answered 16/9, 2014 at 9:23 Comment(0)
I
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>
Ise answered 29/9, 2014 at 14:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.