In a .csproj file, what is for?

2020-05-16 13:14发布

How is

<None Include="C:\foo.bar" />

different from

<Content Include="C:\foo.bar" />

?

标签: c# csproj
8条回答
地球回转人心会变
2楼-- · 2020-05-16 13:39

You need None in a template project file to include files you define in the .vstemplate otherwise they are lost in the creation & translation process. They get left behind in the temp folder it uses to build everything and then deleted shortly after.

查看更多
何必那么认真
3楼-- · 2020-05-16 13:43

In my case .Pubxml is one of those files among None list. It's not meant for solution building or as a static file for web project. But to publish the site to Azure, the configurations are present in this.

As per Microsoft article these are the major types we see among .csproj file tags:

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.

查看更多
不美不萌又怎样
4楼-- · 2020-05-16 13:48

One difference is how they get published; "None" items don't get included in a publish, "Content" items do; for example, on the "Application Files" dialog on the Publish tab.

查看更多
Summer. ? 凉城
5楼-- · 2020-05-16 13:56

The MSDN article on the build action property explains the differences.

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.

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.

查看更多
甜甜的少女心
6楼-- · 2020-05-16 13:57

Content files are not included in a build, but are included in a publish.

None files are not included in a build or publish, unless they are configured that way by you. For instance, a "Copy to Output Directory" setting of "Always" or "Newer", will cause them to be included in both a build and publish.

查看更多
狗以群分
7楼-- · 2020-05-16 13:59

I am not 100% sure (I read the MSDN description of Build Action property) but just copying that answer from MSDN to StackOverflow does not answer the question completely for me.

The difference of None and Content only has an effect on Web projects. For a command line project, WinForm project or UnitTest project (in my case) etc. None and Content have no different behavior.

MSDN: "project output group" or "Content output group" only terms used in a Web project, right?

查看更多
登录 后发表回答