What are the various “Build action” settings in Visual Studio project properties and what do they do?

后端 未结 7 883
-上瘾入骨i
-上瘾入骨i 2020-11-22 04:22

For the most part, you just take whatever Visual Studio sets it for you as a default... I\'m referring to the BuildAction property for each file selected in Solution Explore

相关标签:
7条回答
  • 2020-11-22 05:00

    VS2010 has a property for 'Build Action', and also for 'Copy to Output Directory'. So an action of 'None' will still copy over to the build directory if the copy property is set to 'Copy if Newer' or 'Copy Always'.

    So a Build Action of 'Content' should be reserved to indicate content you will access via 'Application.GetContentStream'

    I used the 'Build Action' setting of 'None' and the 'Copy to Output Direcotry' setting of 'Copy if Newer' for some externally linked .config includes.

    G.

    0 讨论(0)
  • 2020-11-22 05:08

    From the documentation:

    The BuildAction property indicates what Visual Studio does with a file when a build is executed. BuildAction can have one of several values:

    None - The file is not included in the project output group and is not compiled in the build process. An example is a text file that contains documentation, such as a Readme file.

    Compile - The file is compiled into the build output. This setting is used for code files.

    Content - The file is not compiled, but is included in the Content output group. For example, this setting is the default value for an .htm or other kind of Web file.

    Embedded Resource - This file is embedded in the main project build output as a DLL or executable. It is typically used for resource files.

    0 讨论(0)
  • 2020-11-22 05:09

    In VS2008, the doc entry that seems the most useful is:

    Windows Presentation Foundation Building a WPF Application (WPF)

    ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/wpf_conceptual/html/a58696fd-bdad-4b55-9759-136dfdf8b91c.htm

    ApplicationDefinition Identifies the XAML markup file that contains the application definition (a XAML markup file whose root element is Application). ApplicationDefinition is mandatory when Install is true and OutputType is winexe. A WPF application and, consequently, an MSBuild project can only have one ApplicationDefinition.

    Page Identifies a XAML markup file whose content is converted to a binary format and compiled into an assembly. Page items are typically implemented in conjunction with a code-behind class.

    The most common Page items are XAML files whose top-level elements are one of the following:

    Window (System.Windows..::.Window).
    
    Page (System.Windows.Controls..::.Page).
    
    PageFunction (System.Windows.Navigation..::.PageFunction<(Of <(T>)>)).
    
    ResourceDictionary (System.Windows..::.ResourceDictionary).
    
    FlowDocument (System.Windows.Documents..::.FlowDocument).
    
    UserControl (System.Windows.Controls..::.UserControl).
    

    Resource Identifies a resource file that is compiled into an application assembly. As mentioned earlier, UICulture processes Resource items.

    Content Identifies a content file that is distributed with an application. Metadata that describes the content file is compiled into the application (using AssemblyAssociatedContentFileAttribute).

    0 讨论(0)
  • 2020-11-22 05:12

    How about this page from Microsoft Connect (explaining the DesignData and DesignDataWithDesignTimeCreatableTypes) types. Quoting:

    The following describes the two Build Actions for Sample Data files.

    Sample data .xaml files must be assigned one of the below Build Actions:

    DesignData: Sample data types will be created as faux types. Use this Build Action when the sample data types are not creatable or have read-only properties that you want to defined sample data values for.

    DesignDataWithDesignTimeCreatableTypes: Sample data types will be created using the types defined in the sample data file. Use this Build Action when the sample data types are creatable using their default empty constructor.

    Not so incredibly exhaustive, but it at least gives a hint. This MSDN walkthrough also gives some ideas. I don't know whether these Build Actions are applicable for non-Silverlight projects also.

    0 讨论(0)
  • 2020-11-22 05:20
    • None: The file is not included in the project output group and is not compiled in the build process. An example is a text file that contains documentation, such as a Readme file.

    • Compile: The file is compiled into the build output. This setting is used for code files.

    • Content: Allows you to retrieve a file (in the same directory as the assembly) as a stream via Application.GetContentStream(URI). For this method to work, it needs a AssemblyAssociatedContentFile custom attribute which Visual Studio graciously adds when you mark a file as "Content"

    • Embedded resource: Embeds the file in an exclusive assembly manifest resource.

    • Resource (WPF only): Embeds the file in a shared (by all files in the assembly with similar setting) assembly manifest resource named AppName.g.resources.

    • Page (WPF only): Used to compile a xaml file into baml. The baml is then embedded with the same technique as Resource (i.e. available as `AppName.g.resources)

    • ApplicationDefinition (WPF only): Mark the XAML/class file that defines your application. You specify the code-behind with the x:Class="Namespace.ClassName" and set the startup form/page with StartupUri="Window1.xaml"

    • SplashScreen (WPF only): An image that is marked as SplashScreen is shown automatically when an WPF application loads, and then fades

    • DesignData: Compiles XAML viewmodels so that usercontrols can be previewed with sample data in Visual Studio (uses mock types)

    • DesignDataWithDesignTimeCreatableTypes: Compiles XAML viewmodels so that usercontrols can be previewed with sample data in Visual Studio (uses actual types)

    • EntityDeploy: (Entity Framework): used to deploy the Entity Framework artifacts

    • CodeAnalysisDictionary: An XML file containing custom word dictionary for spelling rules

    0 讨论(0)
  • 2020-11-22 05:24
    • Fakes: Part of the Microsoft Fakes (Unit Test Isolation) Framework. Not available on all Visual Studio versions. Fakes are used to support unit testing in your project, helping you isolate the code you are testing by replacing other parts of the application with stubs or shims. More here: https://msdn.microsoft.com/en-us/library/hh549175.aspx
    0 讨论(0)
提交回复
热议问题