asp.net-mvc /obj/debug 破坏构建中的 TemporaryGeneratedFile_[guid]

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12405619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 02:14:31  来源:igfitidea点击:

TemporaryGeneratedFile_[guid] in /obj/debug breaking build

asp.net-mvc.net-4.5stylecop

提问by NikolaiDante

I have 3 temporary files being created in obj/debug:

我在 obj/debug 中创建了 3 个临时文件:

E.g.

例如

  • TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
  • TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
  • TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
  • TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
  • TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
  • TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

(The guids don't seem to change even after a solution clean)

(即使在解决方案清洁后,guids 似乎也没有改变)

My build is failing because:

我的构建失败,因为:

SA1633: The file has no header, the header Xml is invalid, or the header is not located at the top of the file.

SA1633:文件没有标题,标题 Xml 无效,或标题不在文件顶部。

I don't want to turn the StyleCop rule off. How do I find out what is creating these temporary files?

我不想关闭 StyleCop 规则。如何找出创建这些临时文件的原因?

The site is an asp.net MVC 4 site, with 5 models, 4 controllers, 2 classes, 2 aspx web pages and 1 service reference, which numerically don't seem to tally with the 3 files.

该站点是一个 asp.net MVC 4 站点,具有 5 个模型、4 个控制器、2 个类、2 个 aspx 网页和 1 个服务参考,在数字上似乎与 3 个文件不符。

Any pointers?

任何指针?

Edit:If I change framework from 4.5 back to 4 these files go away and the build is successful.

编辑:如果我将框架从 4.5 改回 4,这些文件就会消失并且构建成功。

My version of StyleCop is 4.4, I'm more than open to finding a way to get it to ignore obj/debug

我的 StyleCop 版本是 4.4,我非常愿意找到一种方法让它忽略 obj/debug

采纳答案by NikolaiDante

In the parsers block of a StyleCop.Settings file add an entry for these files: The value is a regex, so a tighter one for matching a guid could be used, but these meets my need for now.

在 StyleCop.Settings 文件的解析器块中,为这些文件添加一个条目:该值是一个正则表达式,因此可以使用更紧密的匹配 guid 的方法,但这些满足我现在的需要。

  <Parsers>
    <Parser ParserId="Microsoft.StyleCop.CSharp.CsParser">
      <ParserSettings>
        <BooleanProperty Name="AnalyzeDesignerFiles">False</BooleanProperty>
        <CollectionProperty Name="GeneratedFileFilters">
          <Value>\.g\.cs$</Value>
          <Value>\.generated\.cs$</Value>
          <Value>\.g\.i\.cs$</Value>
          <Value>TemporaryGeneratedFile_.*\.cs$</Value>
        </CollectionProperty>
      </ParserSettings>
    </Parser>
  </Parsers>

回答by Rajesh

I solved this issue by going to the project solution (whose build) was giving this error.

我通过转到项目解决方案(其构建)出现此错误来解决此问题。

  1. right click on the project and unload the project.
  2. Then right click on the project and edit the .csproj file.
  3. Look for these temp (problematic) generated files. (see example code)
  4. remove this file references from the .csproj file.
  5. Right click on project and load back the project.
  6. Rebuild the solution.
  7. Its good to go now...
  1. 右键单击该项目并卸载该项目。
  2. 然后右键单击该项目并编辑 .csproj 文件。
  3. 查找这些临时(有问题)生成的文件。(见示例代码)
  4. 从 .csproj 文件中删除此文件引用。
  5. 右键单击项目并加载回项目。
  6. 重建解决方案。
  7. 现在去就好了……

they look like this in the csproj file:

它们在 csproj 文件中看起来像这样:

<Compile Include="src\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs" />
<Compile Include="src\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs" />
<Compile Include="src\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs" />

回答by Vlado

The 3 files with "TemporaryGeneratedFile_" prefix are auto-generated by the Microsoft.WorkflowBuildExtensions.targets file most likely imported via the chain:

带有“TemporaryGeneratedFile_”前缀的 3 个文件是由 Microsoft.WorkflowBuildExtensions.targets 文件自动生成的,最有可能通过链导入:

  • *.csproj -->
  • Microsoft.CSharp.targets -->
  • Microsoft.Common.targets -->
  • Microsoft.WorkflowBuildExtensions.targets
  • *.csproj -->
  • Microsoft.CSharp.targets -->
  • Microsoft.Common.targets -->
  • Microsoft.WorkflowBuildExtensions.targets

They are generated under the intermediate output path pointed by the $(IntermediateOutputPath)MSBuild property, usually something like obj\debug. One way to deal with the StyleCop warnings/errors about these auto-generated files is to tell StyleCop to skip any *.cs files under the $(IntermediateOutputPath). For example, include the following item in your project:

它们是在$(IntermediateOutputPath)MSBuild 属性指向的中间输出路径下生成的,通常类似于obj\debug. 处理有关这些自动生成文件的 StyleCop 警告/错误的一种方法是告诉 StyleCop 跳过 .cs 文件下的任何 *.cs 文件$(IntermediateOutputPath)。例如,在您的项目中包含以下项目:

<ItemGroup>
    <ExcludeFromStyleCop Include="$(IntermediateOutputPath)\**\*.cs" />
</ItemGroup>

ExcludeFromStyleCopis an item name recognized by the StyleCop.targets file to exclude files from analysis during a build (at least for StyleCop 4.7). The double star **is MSBuild syntax for searching recursively under a folder.

ExcludeFromStyleCop是 StyleCop.targets 文件识别的项目名称,用于在构建期间从分析中排除文件(至少对于 StyleCop 4.7)。双星**是用于在文件夹下递归搜索的 MSBuild 语法。

The new item might show up in the Solution Explorer in Visual Studio. If that is undesirable it can be hidden by using the 'Visible' item metadata:

新项目可能会显示在 Visual Studio 的解决方案资源管理器中。如果这是不受欢迎的,可以使用“可见”项目元数据将其隐藏:

<ItemGroup>
    <ExcludeFromStyleCop Include="$(IntermediateOutputPath)\**\*.cs" >
        <Visible>False</Visible>
    </ExcludeFromStyleCop>
</ItemGroup>

Similar approach can be used to exclude other files if necessary. I hope that helps.

如有必要,可以使用类似的方法排除其他文件。我希望这有帮助。

回答by John

I was helping a colleague who had added a new project to our main VS solution and who got these same 3 errors. I went through the suggested steps above with him but did not have any success in fixing it. After this, I discovered he had missed one of the steps we perform when adding a new project within our solution that uses Code Analysis and StyleCop. He had forgot to add the Settings.StyleCop file to his project :)

我正在帮助一位同事,他在我们的主要 VS 解决方案中添加了一个新项目,但遇到了同样的 3 个错误。我和他一起完成了上面建议的步骤,但没有成功修复它。在此之后,我发现在我们的解决方案中添加一个使用代码分析和 StyleCop 的新项目时,他错过了我们执行的步骤之一。他忘了将 Settings.StyleCop 文件添加到他的项目中 :)

回答by erupnu

I have recently ran into this same problem out of nowhere.

我最近突然遇到了同样的问题。

For me, I was able to overcome this by opening the .csproj files for each project, then remove the following line:

对我来说,我能够通过打开每个项目的 .csproj 文件来克服这个问题,然后删除以下行:

<Import Project="$(SolutionDir)\CodeAnalize\Microsoft.StyleCop.targets" />

After re-opening the solution, it was able to build everything without an error.

重新打开解决方案后,它能够无错误地构建所有内容。

回答by Mortada Issa

I faced a similar problem and solved it as follow:

我遇到了类似的问题并解决了以下问题:

Deleted debug in bin folderin addition to debug in obj folderrebuild and it worked

除了在 obj 文件夹重建中进行调试之外,还删除了 bin 文件夹中的调试并且它起作用了