PostSharp构建时错误:“System.IO.IOException:进程无法访问文件'C:\ ... \ MyProjectOutputDll.dll'”

时间:2015-01-05 11:23:43

标签: c# postsharp

我有几个依赖PostSharp的项目。经常(超过50%的时间)我的构建以此错误结束:

Error   19  Unhandled exception (4.0.34.0, 32 bit, CLR 4.5, Release): System.IO.IOException: The process cannot access the file 'C:\SolutionPath\ProjectPath\obj\Debug\ProjectName.dll' because it is being used by another process.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at ^Up6wxUIUnN6a.^8KD6D2SV(String _0)
   at ^cyC/TYSlPGB/.^wvPm(^RtksFin57NJ8 _0, ^8gP93Xsl\+Imn _1)
   at PostSharp.Sdk.Extensibility.Tasks.CompileTask.Execute()
   at PostSharp.Sdk.Extensibility.Project.ExecutePhase(String phase)
   at PostSharp.Sdk.Extensibility.Project.Execute()
   at PostSharp.Hosting.PostSharpObject.ExecuteProjects()
   at PostSharp.Hosting.PostSharpObject.InvokeProject(ProjectInvocation projectInvocation). C:\SolutionPath\ProjectPath\ProjectFile.csproj  ProjectName

错误中提到的项目有时会改变(例如)ProjectA,有时会改变SomeOtherProject等等。很多时候,这个错误在几个项目中出现两次甚至更多。

我在某些地方覆盖LocationInterceptionAspect.CompileTimeValidate方法,可能是因为它会发生一些碰撞吗?

我还使用写入日志文件的记录器(OnMethodBoundaryAspectOnExceptionAspect),但它没有编译时方法......

我该如何解决?

1 个答案:

答案 0 :(得分:1)

错误意味着PostSharp无法将输出程序集写入磁盘。这不应该自己发生,因为MSBuild保证在依赖完成编译后执行依赖项目。

最可能的情况是您在MSBuild外部访问程序集而没有设置正确的项目依赖项(请参阅Visual Studio中解决方案的上下文菜单选项)。

请检查以下内容:

  1. C#/ VB构建事件。
  2. 自定义构建步骤。
  3. 方面方法中的动态装配加载。
  4. 所有这些都不应该访问当前项目没有依赖关系集的项目的输出文件。如果是这样,失败将随机描述。