简体   繁体   中英

MSBuild Copying from IntermediateOutputPath After Build Completion

I am using Afterthought (similar to PostSharp) to apply post build changes to some code by modifying the output assembly. Currently, my project file has something like this within (abbreviated):

<Target Name="AfterBuild">
  <AfterThoughtTask TargetAssembly="$(TargetPath)" AmendWith="$(TargetDir)Amendments.dll" />
</Target>

Basically it's saying: after the build, use the AfterThoughtTask which runs a process to modify the output assembly with code found in Amendments.dll. This works just fine as I'd expect, and the MyProject.dll output to MyProject\\bin\\Debug\\MyProject.dll is amended with the additional code.

Then I make this slight change to my project file:

<PropertyGroup>
  <OutputPath>SomeOtherProjectLocation\bin\</OutputPath>
</PropertyGroup>

So all I've done is change the output path. Now I debug AfterThoughtTask , and hit a breakpoint after all the code has been executed. When I'm stopped on this breakpoint, the file SomeOtherProjectLocation\\bin\\MyProject.dll (which is the file I intended to amend, sitting in the folder I expect it to be in) appears to be amended (has a file size of 117kb vs 103kb when unamended). It appears as if things are going fine at this point. Then I release the breakpoint, and suddenly the file size drops back to 103kb, somehow getting replaced with the original unamended file. Looking at the diagnostic build report, AfterThoughtTask is the very last task run with no reported file copies after it.

Running again at the same breakpoint, I see that the file sitting in the IntermediateOutputPath directory (obj\\Debug) is still 103kb (unamended), so I try to see if that is the file that is overwriting the amended one. When I'm at the breakpoint (the end of the task execution, but before control is given back to the build), I rename the file in the IntermediateOutputPath directory to MyProject.dll_hidden. I get no errors, but my file is no longer written over.

So I can only assume that the file is being copied from the IntermediateOutputPath directory over the target file, but the build log doesn't seem to indicate this, and I don't understand why changing the OutputPath would make it happen this way vs. how it was acting before with the default OutputPath . Anyone have any guidance here? Thanks in advance.

Build it with command line and set verbosity to diag (/v:diag). Pipe output to logfile and dig it down - usually with diag output you can easily locate source of problem (or post log here).

Also check following - if you alter global OutputPath - other build projects will write to that folder - build with unaltered OutputPath and find what project's dll matches the 117kb size.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM