Unity Build Fails with "Duplicate Assembly Definition" Error - How to Fix
Your Unity build fails with a "Duplicate Assembly Definition" error (or similar wording such as "Duplicate assembly name" or "Assembly 'X' is already defined"). This usually means two or more Assembly Definition files (.asmdef) are producing the same assembly name, or the same assembly is being included in a way that conflicts. This guide walks you through how to find and fix the duplicate so your build succeeds.
The Problem
When building your Unity project, you may see:
- "Duplicate Assembly Definition"
- "Assembly 'AssemblyName' is already defined"
- "CS0579: Duplicate 'AssemblyDefinition' attribute"
- Build fails with duplicate assembly or asmdef errors
These occur when Unity sees the same assembly identity more than once during compilation.
Why This Happens
Common causes:
Duplicate assembly names:
- Two or more
.asmdeffiles use the same Name (thenamefield in the JSON). Every asmdef must have a unique name. - A copied or renamed folder left an asmdef with the old name alongside a new one.
Nested asmdefs with the same name:
- An assembly definition in a subfolder has the same name as one in a parent (or another branch). Unity discovers both and reports a duplicate.
Package or plugin assemblies:
- A package or imported plugin ships an asmdef whose name clashes with one in your project (e.g. both named
Assembly-CSharpor a custom name you also use).
Version control or merge issues:
- Duplicate
.asmdeffiles or duplicatenamevalues introduced by merges or copy-paste.
Solution 1: Find and Fix Duplicate Assembly Names
Unity compiles each .asmdef into an assembly; the Name in the file is the assembly name. Two asmdefs with the same name cause the duplicate assembly definition error.
Step 1: List All Assembly Definition Names
- In Unity, open the Project window.
- Use the search bar and type:
t:AssemblyDefinitionAsset(or search forasmdef). - Select each
.asmdefand in the Inspector check the Name field (or open the file and check thenameproperty in JSON). - Write down every name. Look for two or more asmdefs sharing the same name.
Step 2: Rename One of the Duplicates
- Choose which asmdef should keep the name and which should be renamed (usually the one in the wrong place or the duplicate you don’t need).
- Select the asmdef you want to rename.
- In the Inspector, change Name to a unique value (e.g.
MyGame.Gameplay,MyGame.UI). Use a consistent naming scheme to avoid future clashes. - If any other assembly references this one, update those
.asmdeffiles’ Assembly References to use the new name. - Save and let Unity recompile, then try the build again.
Pro tip: Use names that reflect folder or feature (e.g. Game.Camera, Game.Inventory) so names stay unique and readable.
Solution 2: Remove or Consolidate Duplicate asmdef Files
Sometimes the fix is to remove a duplicate file or merge folders so only one asmdef defines that assembly.
Step 1: Locate Duplicate asmdef Files
- Search the project for
.asmdef(e.g. in File Explorer or Finder at the project root). - Check for:
- Two
.asmdeffiles with the samenamein different folders. - A copied folder that brought in a second asmdef with the same name.
- An old or backup asmdef (e.g.
MyAssembly.asmdefandMyAssembly.asmdef.bakor a copy in a subfolder).
- Two
Step 2: Remove or Merge
- If one asmdef is redundant: Delete the duplicate
.asmdeffile. Move any scripts that should stay in an assembly into the folder of the asmdef you kept, then reimport. - If you need two separate assemblies: Keep both but give them different Name values (see Solution 1).
- If a package/plugin has the same name: Rename your project’s asmdef to something unique; avoid renaming the package’s asmdef so updates don’t overwrite it.
After changes, let Unity reimport and try building again.
Solution 3: Fix References After Renaming
After renaming or removing an assembly, other assemblies that referenced it must be updated.
- Search for
.asmdeffiles that might reference the old name. - Open each in the Inspector (or in a text editor).
- In Assembly References, remove the old assembly name and add the new one if you renamed it.
- Fix any scripts that were in the removed asmdef’s folder (move them under the correct asmdef or assign a new asmdef).
- Save and reimport; then build again.
Solution 4: Clean and Rebuild
If you’re not sure where the duplicate comes from, a clean reimport can help.
- Close Unity.
- In your project folder, delete the Library folder (Unity will regenerate it).
- Optionally delete the Temp folder if present.
- Reopen the project and wait for Unity to reimport everything.
- Try building again.
If the duplicate was from a stale cache, this may clear it. If the error persists, the duplicate is in your project (two asmdefs with the same name); use Solutions 1 and 2 to fix it.
Verification
After applying a fix:
- Build the project (e.g. File > Build and Run or your usual build pipeline).
- Confirm the "Duplicate Assembly Definition" (or duplicate assembly name) error is gone.
- Run a quick test in the Editor (Play mode) to ensure scripts in the changed assemblies still work.
- If you use multiple build targets, test at least one other (e.g. standalone and one platform).
Alternative Fixes and Edge Cases
- Same name in different platforms: If you use
includePlatforms/excludePlatforms, ensure you don’t have two asmdefs that end up with the same effective name for the same platform. - Packages: If a package’s asmdef clashes with yours, rename yours; do not modify the package’s asmdef inside the package cache.
- Git/merge: If the duplicate appeared after a merge, check for duplicate filenames or duplicate
namevalues in asmdefs in the changed files.
Prevention Tips
- Unique names: Give every
.asmdefa unique Name (e.g. prefix with project or module:MyGame.Core,MyGame.AI). - Naming convention: Use a consistent scheme (e.g.
Project.Module) so duplicates are obvious when you add new asmdefs. - Avoid copy-paste asmdefs: When duplicating folders, rename the copied asmdef and its Name immediately.
- Review after merge: After merging branches, search for
asmdefand spot-check names and duplicate files.
Related Problems and Links
- Missing Assembly References – Unity 2026.3 LTS Build Fails with Missing Assembly References Error – different error, often related to references rather than duplicates.
- Scripting Backend / Build Fails – Unity Build Fails with Scripting Backend Error – for general build and backend issues.
- Unity documentation – Assembly definitions – official reference for asmdef and assembly structure.
Bookmark this page for quick reference the next time you see a duplicate assembly definition error. If this fix helped, share it with other Unity devs who hit the same build error.