Batch files in Visual Studio 2008

2019-07-08 09:52发布

问题:

I need help with a very frustrating problem with Visual Studio 2008.
I have a project in C# which calls, during the pre-compilation phase, a batch file which copies some dlls into a sub-directory of the project itself. It often happens that Visual Studio reports an error caused by the execution of the batch file: it says that the execution had terminated with code 1. After that, the only solution to compile again the project is restarting Visual Studio. Once restarted, the compilation doesn't report any problem.
Is there anyone who report the same problem?
Do you know a way to resolve it?
Thank you very much.

回答1:

Use a <copy/> task instead. This will give you better error handling.

Example to copy all DLLs from C:\SourceDir to LocalDir:

<ItemGroup>
  <SourceFiles Include="C:\SourceDir\*.dll" />
</ItemGroup>
<Copy SourceFiles="@(SourceFiles )" DestinationFolder="LocalDir\" />

See also the MSDN CopyTask Reference.

The root cause is probably the studio itself having still the assemblies open via the "Visual Studio hosting process". You can disable this in the project's properties under "Debug", "Enable the Visual Studio hosting process". See the Debugging and the Hosting Process article for details.