在 .csproj 文件中,是什么? 为了?

发布于 2024-07-25 14:05:11 字数 158 浏览 11 评论 0原文

与有何

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

不同

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

How is

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

different from

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

?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

弥枳 2024-08-01 14:05:11

有关 的 MSDN 文章build action 属性解释了这些差异。

- 该文件不包含在项目输出组中,并且不在构建过程中进行编译。 一个示例是包含文档的文本文件,例如自述文件。

内容 - 文件未编译,但包含在内容输出组中。 例如,此设置是 .htm 或其他类型的 Web 文件的默认值。

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.

酒几许 2024-08-01 14:05:11

一个区别在于它们的发布方式; “无”项目不会包含在发布中,“内容”项目则会包含在内; 例如,在“发布”选项卡上的“应用程序文件”对话框中。

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.

行雁书 2024-08-01 14:05:11

我不是 100% 确定(我阅读了 Build Action 属性的 MSDN 描述),但仅仅将该答案从 MSDN 复制到 StackOverflow 并不能完全回答我的问题。

NoneContent 的区别仅对 Web 项目有影响。 对于命令行项目、WinForm 项目或 UnitTest 项目(在我的例子中)等。内容没有不同的行为。

MSDN:“项目输出组”或“内容输出组”只是 Web 项目中使用的术语,对吧?

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?

爱要勇敢去追 2024-08-01 14:05:11

在我的情况下,我的 MSBuild 文件有一个用于图像资源的 ItemGroup,如下所示:

  <ItemGroup>
    <Content Include="Resources\image001.png" />
    <Content Include="Resources\image002.png" />
    <Content Include="Resources\image003.png" />
    <Content Include="Resources\image004.png" />
    <None Include="Resources\image005.png" />
    <None Include="Resources\image006.png" />
    <None Include="Resources\image007.png" />
  </ItemGroup>

虽然我的项目构建得很好,但这让我想知道为什么我混合了 Content我的 ItemGroup 中的 None 项目类型元素。 这篇 MSDN 文章(适用于 Visual Studio 2010)给了我我正在寻找的指导:

请注意,当资源编辑器添加图像时,它会设置Build
操作
更改为,因为 .resx 文件引用了该图像
文件。 在构建时,图像被拉入 .resources 文件中
从 .resx 文件创建。 然后可以轻松访问该图像
通过为 .resx 文件自动生成的强类型类。
因此,您不应将此设置更改为嵌入式
资源
,因为这样做会在其中包含两次图像
大会。

解决方案:按照此指导,使用文本编辑器,我将 Content 项类型元素更改为 None

另外,有关 MSBuild 项目的概述,请参阅此 MSDN 文章

In my situation, my MSBuild file had an ItemGroup for image resources that appeared as follows:

  <ItemGroup>
    <Content Include="Resources\image001.png" />
    <Content Include="Resources\image002.png" />
    <Content Include="Resources\image003.png" />
    <Content Include="Resources\image004.png" />
    <None Include="Resources\image005.png" />
    <None Include="Resources\image006.png" />
    <None Include="Resources\image007.png" />
  </ItemGroup>

While my project was building fine, this left me wondering why I had a mix of Content and None item type elements in my ItemGroup. This MSDN article (for Visual Studio 2010) gave me the guidance I was looking for:

Note that when the resource editor adds an image, it sets Build
Action
to None, because the .resx file references the image
file. At build time, the image is pulled into the .resources file
created out of the .resx file. The image can then easily be accessed
by way of the strongly-typed class auto-generated for the .resx file.
Therefore, you should not change this setting to Embedded
Resource
, because doing this would include the image two times in
the assembly.

Resolution: With this guidance, using a text editor, I changed the Content item type elements to None.

Also, for an overview of MSBuild items, see this MSDN article.

∞梦里开花 2024-08-01 14:05:11

内容文件不包含在构建中,但包含在发布中。

文件不包含在构建或发布中,除非您以这种方式配置它们。 例如,“复制到输出目录”设置为“始终”或“较新”,将导致它们包含在构建和发布中。

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.

盗梦空间 2024-08-01 14:05:11

我有一个不包含可编译项目的项目(它存储用于 jasmine 单元测试的 html 和 javascript)。

有一天,我的解决方案(包含所述项目)停止编译,说“项目中不存在目标“构建””。

我添加了一个导入来引入编译器,它在我的机器上运行良好,但在构建服务器上使用 msbuild 失败。

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

然后我将一行从 改为

<None Include="SpecRunner.html" />

<Content Include="SpecRunner.html" />

它也可以在构建服务器上运行。

I have a project that contains no compilable items (it stores html and javascript for jasmine unit tests).

One day my solution (that contained said project) stopped compiling saying "The target "Build" does not exist in the project".

I added an import to bring in the compiler, which worked fine on my machine but failed using msbuild on the build server.

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

I then changed a line from

<None Include="SpecRunner.html" />

to

<Content Include="SpecRunner.html" />

and it worked on the build server as well.

夏日落 2024-08-01 14:05:11

您不需要在模板项目文件中包含您在 .vstemplate 中定义的文件,否则它们会在创建和创建过程中丢失。 翻译过程。 它们被留在用于构建所有内容的临时文件夹中,然后不久后被删除。

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.

天邊彩虹 2024-08-01 14:05:11

就我而言,.Pubxml列表中的文件之一。 它不适用于解决方案构建或作为 Web 项目的静态文件。 但要将站点发布到 Azure,配置就在此处。

根据 Microsoft 文章,这些是我们在 .csproj 文件标记中看到的主要类型:

无 - 该文件不包含在项目输出组中,并且不包含在项目输出组中。
在构建过程中编译。 一个示例是一个文本文件,其中包含
文档,例如自述文件。

编译 - 文件被编译到构建输出中。 这个设置是
用于代码文件。

内容 - 文件未编译,但包含在内容中
输出组。 例如,此设置是默认值
.htm 或其他类型的 Web 文件。

嵌入式资源 - 该文件嵌入在主项目构建中
输出为 DLL 或可执行文件。 它通常用于资源
文件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文