Posts
1150
Comments
891
Trackbacks
1
The item 'T4MVC1.cs' cannot be deleted

I ran into this problem about a month or two ago, and don’t remember how I fixed it.

Every time I build my solution which uses T4MVC, I get this error unless I manually delete the file.  Also, note that it is “T4MVC1” and not “T4MVC.”  This happened the last time as well, where somehow the solution thinks it needs to name the file differently.

I will post the solution whenever I figure out what it is so that it is documented for myself the next time it happens.

posted on Sunday, February 06, 2011 3:13 PM Print
Comments
Gravatar
# re: The item 'T4MVC1.cs' cannot be deleted
Korayem
5/7/2011 5:47 PM
It happens randomly

1-I have to uninstall-package T4MVC
2-Restart Visual Studio
3-Install-Package T4MVC

Any updates on how to fix this?
Gravatar
# re: The item 'T4MVC1.cs' cannot be deleted
jdn
5/7/2011 6:55 PM
Unfortunately, not yet.

Once I get back to that solution, I will try to figure out a permanent solution.
Gravatar
# re: The item 'T4MVC1.cs' cannot be deleted
Steve Hiner
11/12/2012 5:19 PM
I found that I could build again after disabling the AutoT4MVC extension.
Gravatar
# re: The item 'T4MVC1.cs' cannot be deleted
Chad
4/22/2013 4:40 AM
I keep hitting this wall as well, sometimes removing AutoT4MVC resolves it, sometimes not..

This blog post is just about the only thing that mentions the issue.
Gravatar
# re: The item 'T4MVC1.cs' cannot be deleted
David Tansey
6/9/2014 2:34 PM
Encountering the same issue and having difficulty figured out how to get around it.
Gravatar
# re: The item 'T4MVC1.cs' cannot be deleted
phuso
12/10/2014 4:28 AM
in the .csproj chamnge the value of <LastGenOutput> to "T4MVC.cs2"
Gravatar
# re: The item 'T4MVC1.cs' cannot be deleted
Sergey
12/13/2014 6:29 AM
Thanks phuso!! this fixed my issue, and it works like a charm with AutoT4MVC now.
Gravatar
# re: The item 'T4MVC1.cs' cannot be deleted
jdn
12/13/2014 1:16 PM
@phuso:

Thanks, it's good to know there's a workaround.
Gravatar
# re: The item 'T4MVC1.cs' cannot be deleted
Dave Amour
1/29/2016 12:53 AM
In Visual Studio right click on the web project and Unload Project. Right click again and click Edit csproj file.

Find a node like this:

<Compile Include="T4MVC\T4MVC1.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>T4MVC.tt</DependentUpon>
</Compile>

Delete the whole thing, save and close the file.

Right clik on the web project again and Reload Project.

Build and all shoud be fine.
Gravatar
# re: The item 'T4MVC1.cs' cannot be deleted
xmarwin
3/15/2017 4:17 AM
Thanks Dave Amour, you just saved my day - out of nowhere my T4MVC.cs got renamed to T4MVC1.cs and only changing project file returned it back.

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 3 and 2 and type the answer here: