.NET Build Error MSB3073 Fix
In this tutorial, you'll learn about .net build error msb3073 fix. We cover key concepts, practical examples, and best practices.
The Problem
Your .NET build fails with:
error MSB3073: The command "xcopy /Y ..\lib\*.dll bin\" exited with code 1.
MSB3073 means a post-build event, pre-build event, or custom build step returned a non-zero exit code. MSBuild treats any non-zero exit as failure.
Quick Fix
Step 1: Locate the failing command
The error message shows the exact command that failed. Open your .csproj and find the corresponding <Target> or event:
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="xcopy /Y ..\lib\*.dll bin\" />
</Target>
Step 2: Test the command manually
WRONG -- assuming the command works because it looks correct:
# Run from Package Manager Console or terminal in the project directory
xcopy /Y ..\lib\*.dll bin\
If this fails, check if source paths and target directories exist.
RIGHT -- verify paths and create missing directories:
if not exist bin mkdir bin
xcopy /Y ..\lib\*.dll bin\
Step 3: Handle exit codes gracefully
WRONG -- ignoring exit codes:
<Exec Command="copy ..\lib\*.dll bin\" />
RIGHT -- use ContinueOnError or check exit codes:
<Exec Command="copy ..\lib\*.dll bin\" ContinueOnError="WarnAndContinue" />
Or force the command to always succeed:
<Exec Command="xcopy /Y ..\lib\*.dll bin\ || exit 0" />
Step 4: Check file paths and permissions
WRONG -- hardcoded paths that break on other machines:
<Exec Command="copy C:\MyLibs\*.dll bin\" />
RIGHT -- use MSBuild properties:
<Exec Command="copy $(ProjectDir)..\lib\*.dll $(OutDir)" />
Step 5: Use MSBuild Condition attributes
WRONG -- running file-copy steps unconditionally:
<Target Name="CopyLibs" AfterTargets="Build">
<Copy SourceFiles="@(LibFiles)" DestinationFolder="$(OutDir)" />
</Target>
RIGHT -- check if files exist first:
<Target Name="CopyLibs" AfterTargets="Build" Inputs="@(LibFiles)" Outputs="%(LibFiles.Identity)">
<Copy SourceFiles="@(LibFiles)" DestinationFolder="$(OutDir)" />
</Target>
Prevention
- Test all post-build commands in a terminal before adding them to the project file.
- Use MSBuild properties like
$(ProjectDir)and$(OutDir)instead of hardcoded paths. - Add
<Error>or<Warning>tasks withConditionattributes for better diagnostics. - Use
<Copy>tasks instead ofxcopyorcopycommands when possible. - Set
ContinueOnError="true"for non-critical steps to avoid blocking the build.
Common Mistakes with build error
- Using
foldlinstead offoldl'causing stack overflow on large lists - Forgetting
deriving (Show, Eq)on custom data types needed for debugging - Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
These mistakes appear frequently in real-world DOTNET code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro