T4MVC Error - T4 file is blocked or in a non trust

2019-02-01 08:07发布

问题:

I am running Visual Studio 2010 on a Windows 7 virtual machine inside of Parallels Desktop 8 on a Mac Book Pro.

I'm trying to incorporate T4MVC into a new MVC4 project. I installed the T4MVC package from Nuget and immediately started getting this error...

Failed to resolve include text for file:The path '\psf\Home...\T4MVC.tt.hooks.t4' must be either local to this computer or part of your trusted zone. If you have downloaded this template, you may need to 'Unblock' it using the properties page for the template file in Windows Explorer.

I went into the "Properties" menu for the T4MVC.tt.hooks.t4 file, but I could not find any option or button to unblock it.

My assumption is that this problem has something to do with the fact that I'm running on a virtual machine and therefore My project files are not in a trusted location. But I'm not sure how to fix that.

I've been searching around but can't seem to find any answers. Any help would be appreciated.

Thanks

回答1:

In Windows Explorer, right click on the file, and choose Properties. At the bottom of the General tab, there should be an "Unblock" button.



回答2:

This works for me with VS2012:

Using Internet Explorer:

Go to Tools | Internet Options and click the Security tab Under Trusted Sites, click Sites and uncheck “Require https…” Finally add a new entry – it should be the location of your shared folder: “file://folder_name” – note we’re using file instead of https.



回答3:

This happens to me if I run the project of a shared drive through Parallels.

Windows FIX: Fixed by adding the network drive to trusted web sites. Guide (translated from other language OS)

Open Internet Explorer Open Internet settings Safety pane "Trusted websites" "Websites" Untick "require https for all websites in this zone" Add your network drive like x: For me it added "file://psf" Worked for me.



回答4:

The site below has a good example of adding the Parallels share to the trusted zone for use with opening a Visual Studio project without warnings. The same technique should remove this warning for T4.

http://blog.florianb.net/2009/10/31/loading-projects-in-visual-studio-using-the-shared-profile-feature-in-parallels/



回答5:

Use the method to add security zones described here. Add your parallels shared folders under the trusted sites section. You may have to uncheck the require HTTPS box.



回答6:

To allow VS.NET to load things of a network share one needs to add them (shares) to trusted locations. Have a read of this. This will solve the problem for Windows 8 users, when the file is not actually blocked as described above.

To add a location to a full trust list run (obviously amend as required for you environment):

caspol -m -ag 1.2 -url file:///H:/* FullTrust

To verify or list existing trusted locations run:

caspol -lg


回答7:

It's a file protection thing. The work-around was to create new files of the same name and copying in the text from the old files. Since these files were created on my local computer, there was no conflict.

I had this issue with VS2015 / VS2017 when I copied the .ttinclude files from another project. Creating the new .ttinclude file from the project and renaming them was the only solution.



回答8:

None of them worked. The source of my problem was, I formatted my pc and in most of my projects, i hardcoded common,modified version of EF's tt. The path was e:.. before formatting.

After formatted, i removed e drive and used d as the same folder. Projects started failing saying that the path is not accesible, right. I created a very small e drive with junction links after, these error messages came...

failed to resolve include text for file:The path '.tt' must be either local to this computer or part of your trusted zone. If you have downloaded this template, you may need to 'Unblock' it using the properties page for the template file in File Explorer.

What i did to resolve was, changing every single path to d drive in tt files:

<#@ include file="d:\BitBucket\Kahia\EF Templates\EF6 ClientModel.tt"#>

it was actually;

<#@ include file="e:\BitBucket\Kahia\EF Templates\EF6 ClientModel.tt"#>