4

背景:ReSharper的 - 在代码检查包括外部源文件

我们正在利用我们的.NET C#解决方案第三方工具。该工具具有自己的语法并与Visual Studio集成。当我们使用这个工具时,我们在Visual Studio中编写它的标记,然后当我们构建解决方案时,定制工具运行并根据我们写的标记生成一个.cs文件。

这个生成的源文件包含一个版本号,当我们将这些版本控制到版本控制(无尽冲突)时,会导致问题。我们的理解是,不检查生成的源文件是最佳实践。

所以我们排除了SVN生成的.cs文件,然后我们遇到的下一个问题是Visual Studio解决方案引用了这些文件,所以当TeamCity(我们的持续构建/集成软件)去构建解决方案时会立即失败,因为它无法找到这些文件。

然后,我们将这些从解决方案中删除,并将它们从SVN中排除,这固定了原始问题,我们不再检查生成的代码,并且它在TeamCity中正常生成(因为每次都会重新生成文件建立)。

我们现在有一个新问题 - 由于生成的文件不再包含在解决方案中,因此无法找到生成的类,因此智能感知和代码检查失败。该解决方案构建得很好(因为代码在构建期间被重新生成)。

问题

有没有办法告诉ReSharper的,包括在其代码检查产生的.cs文件?这些文件在解决方案的外部,但它们位于obj目录中。

干杯,

泰勒

+0

难道你不能保留解决方案中的文件,并添加一个预生成步骤来生成一个空的.cs文件,如果它不存在?这将保持构建的快乐。我们在我们的项目中使用了一个类似的技术,用于包含开发人员可覆盖的数据库连接字符串如果有帮助,我有一些示例MSBuild目标。 –

+0

嗨RichTea,听起来不错,我很乐意看到你的样品,如果可能的话? – Tyler

回答

2

正如我在评论中提到,一个解决办法是保持生成文件的解决方案(而不是在源代码控制),同时加入了预生成步骤创建空.cs文件(如果真实生成的文件不存在),以便该文件在构建期间始终可用。

在我的项目中,我使用以下MSBuild目标通过使用Touch任务生成空文件。您可能需要进行一些修改 - 就我而言,目标文件实际上是在项目中定义的,而不是在解决方案级别;并且将这些文件的构建操作设置为“无”,这对了解这些目标的工作方式非常重要。

<?xml version="1.0" encoding="utf-8" ?> 
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"> 

<!-- 
Creates empty 'dummy' files for any files that are specified but do not exist. 
To be processed, the following must be true: 

1. The file is included in an ItemGroup called CanCreateDummy, e.g. 
     <ItemGroup> 
     <CanCreateDummy Include="SomeFile.cs" /> 
     </ItemGroup> 
    If you want to specify a CanCreateDummy file in the .csproj file, you would 
    modify the above slightly as follows to prevent it appearing twice: 
     <ItemGroup> 
     <CanCreateDummy Include="SomeFile.cs"> 
      <Visible>false</Visible> 
     </CanCreateDummy> 
     </ItemGroup> 

2. The file is included in the ItemGroup called None. This is normally performed 
    by adding the file to the project in the usual way through Visual Studio, and 
    then setting the file's Build Action property to None. 
--> 
<Target 
    Name="CreateDummyFiles" 
    AfterTargets="BeforeBuild" 
    > 
<!-- 
This voodoo creates the intersection of 2 lists - @(CanCreateDummy) and @(None) 
(this latter item is defined in the project file). We want to create a filtered 
list of all items that are in both these lists, which is called _ProjectDummyFiles. 
See http://blogs.msdn.com/b/msbuild/archive/2006/05/30/610494.aspx for how the 
Condition voodoo works. 
--> 
<CreateItem Include="@(CanCreateDummy)" Condition="'%(Identity)' != '' and '@(None)' != ''" > 
    <Output TaskParameter="Include" ItemName="_ProjectDummyFiles"/> 
</CreateItem> 

<Message 
    Text="Creating dummy settings file @(_ProjectDummyFiles)" 
    Condition=" !Exists('%(_ProjectDummyFiles.FullPath)')" 
     /> 

<Touch 
    AlwaysCreate="true" 
    Files="@(_ProjectDummyFiles)" 
    Condition=" !Exists('%(_ProjectDummyFiles.FullPath)')" 
     /> 

</Target> 
</Project> 

希望这有助于

丰富

+0

感谢队友工作完美非常狡猾的解决方案!起初,我认为它看起来很诡异,但实施后感觉非常干净(考虑到情况:p)。 – Tyler

+0

非常感谢 - 很高兴它的工作。 '这有点哈克,但更重要的是它是可靠的:) –

4

我们也有类似的问题,并不能拿出一个很好的解决方案,所以我写了一个ReSharper的扩展,包括外部代码:

https://resharper-plugins.jetbrains.com/packages/ReSharper.ExternalCode

+0

这应该得到更多upvotes。安装后,您必须将路径添加到外部代码(相对于项目文件夹)并重新加载项目。 – Vincent

+3

ReSharper 9.1是否有版本或解决方法? – Markus