61

In the process of refactoring some code, I encountered several build errors such as these:

Library project file cannot specify ApplicationDefinition element.

The project file contains a property value that is not valid.

How can these errors be resolved?

Community
  • 1
  • 1
dmo
  • 3,993
  • 6
  • 35
  • 39

5 Answers5

136

When you copy and paste files either within a project or to another project, Visual Studio has a nasty habit of not keeping the same BuildAction property. It often changes the build action to a seemingly random value, e.g. ApplicationDefinition, which causes that build error.

Check (in the Visual Studio properties window with the file selected in the Solution Explorer) that each of your .xaml files have a BuildAction property of Page and your code files have a BuildAction property of Compile.

fubaar
  • 2,489
  • 1
  • 21
  • 21
  • 1
    Weird - i split my XAML files into 2 more DLLs. All my pages were marked with AppDef and my App.xaml was marked as Page :) Thanks for the post, they need to either fix the IDE or at the very least improve the error message on this one (shine some light on the cause) – Gishu Oct 05 '10 at 08:58
  • Note that this is not specific for .xaml files, I got the same problem with .ps files (compiled Pixel Shaders) – TGasdf Jun 19 '13 at 11:55
  • 2
    Great post, short and to the point...I've had this issue a number of times and never once thought that it was the build action missing, so I always went to great lengths to work around the issue...thanks for this, you are going to save me a TON of time and frustration now lol – Robert Petz Dec 03 '13 at 17:24
26

You may also see this even though your build actions are set correctly. For example, if you start your project up as an Application, and then later switch it to be a Class Library. In which case you must also remember to delete App.xaml (and the corresponding App.cs).

ouflak
  • 2,458
  • 10
  • 44
  • 49
4

The build action on the Xaml control must be changed from ApplicationDefinition to Page (this property can be accessed by right clicking on the control in the Solution Explorer treeview and selecting properties).

ouflak
  • 2,458
  • 10
  • 44
  • 49
dmo
  • 3,993
  • 6
  • 35
  • 39
3

This is also when we copy paste an Image/XAML File to ClassLibrary Project.

Change the Build Action Property of that image to resources

aditya potdar
  • 357
  • 3
  • 8
1

2 years later and I came searching with the same question, but was only able to use the above comments to rule out other options and eventually find my answer when I noticed the two projects each had the same identically-named .xaml file within a single solution.


Abstract example

1 solution which has 2 projects: PRINTNOTESPROJ and MAKENOTESPROJ.

During development, I used a XAML window in MAKENOTESPROJ which should actually be part of PRINTNOTESPROJ in the Release executables.

Upon switching to Build->Release, I simply clicked-down on "PrintWindow.XAML" (in MAKENOTESPROJ & with child PrintWindow.xaml.cs) and DRAGGED it onto my PRINTNOTESPROJ.

*This is the key. I forgot that doing this only COPIES the related files to the new project [at least in VS 2010]. From this point onward I received your error until I DELETED "PrintWindow.xaml" from my original project MAKENOTESPROJ.

I hope this makes sense... Please comment with questions!

turkinator
  • 905
  • 9
  • 25