在Visual Web Developer中前preSS亚音速ASP.NET MVC示例 [英] SubSonic ASP.NET MVC sample in Visual Web Developer Express
问题描述
在Visual Web Developer中前preSS 2008年亚音速的ASP.NET MVC模板似乎并没有与我添加了一个新的数据库工作。我删除了奇努克数据库和创建了自己的之一。据我所知,在模型文件夹中的文件.TT用于生成code,但他们不这样做(尽管改变的connectionStringName什么,我在web.config中设置)
In Visual Web Developer Express 2008 the SubSonic ASP.NET MVC template doesn't seem to work with a new database I added. I removed the Chinook Database and created my own one. I understand the the .tt files in the Models folder are used to generate code, but they don't (despite changing the ConnectionStringName to what I set in the web.config)
每个.TT文件并选择运行自定义工具不会产生任何点击鼠标右键,除了一条错误消息:
Right clicking on each .tt file and selecting 'Run Custom Tool' does not generate anything, except an error message:
Cannot find custom tool 'TextTemplatingFileGenerator' on this system.
在哪里该工具保持?有在codeTemplates,当你创建一个新的控制器或视图这是用来.TT文件,所以我假定有一个工具,做到这一点。
Where is that tool kept? There are .tt files in CodeTemplates, which are used when you create a new controller or view, so I assume there is a tool that does this.
推荐答案
与<一个沿继href=\"http://stackoverflow.com/questions/786734/subsonic-asp-net-mvc-sample-in-visual-web-developer-ex$p$pss/791415#791415\">Adam's发表评论,你可以在VS防爆preSS做到这一点,但有需要的模板,亚当建议的更改。
Following along with Adam's comment, YOU CAN do this in VS Express, but there are changes required to the template as Adam suggested.
Visual Studio的要求仅用于获取路径活动项目,然后将其用于查找web.config文件和App_Data文件路径。由于这些值是在一个项目中公知的,我们可以硬code替代值
The Visual Studio requirement is only used to get the path to the active project, which is then used to find a web.config file and the app_data path. Since those values are generally known within a project, we can hardcode substitutes values
更新_Settings.tt文件,像这样:
Update the _Settings.tt file like so:
...
const string ConnectionStringName="Chinook";
//Use this when not building inside visual studio standard or higher
//make sure to include the trailing backslash!
const string ProjectPathDefault="c:\\path\\to\\project\\";
...
public EnvDTE.Project GetCurrentProject() {
if (Host is IServiceProvider)
{
IServiceProvider hostServiceProvider = (IServiceProvider)Host;
if (hostServiceProvider == null)
throw new Exception("Host property returned unexpected value (null)");
EnvDTE.DTE dte = (EnvDTE.DTE)hostServiceProvider.GetService(typeof(EnvDTE.DTE));
if (dte == null)
throw new Exception("Unable to retrieve EnvDTE.DTE");
Array activeSolutionProjects = (Array)dte.ActiveSolutionProjects;
if (activeSolutionProjects == null)
throw new Exception("DTE.ActiveSolutionProjects returned null");
EnvDTE.Project dteProject = (EnvDTE.Project)activeSolutionProjects.GetValue(0);
if (dteProject == null)
throw new Exception("DTE.ActiveSolutionProjects[0] returned null");
return dteProject;
}
return null;
}
...
public string GetConfigPath(){
EnvDTE.Project project = GetCurrentProject();
if (project != null)
{
foreach(EnvDTE.ProjectItem item in project.ProjectItems)
{
// if it is the configuration, then open it up
if(string.Compare(item.Name, "Web.config", true) == 0)
{
System.IO.FileInfo info =
new System.IO.FileInfo(project.FullName);
return info.Directory.FullName + "\\" + item.Name;
}
}
return "";
}
else
{
return ProjectPathDefault+"web.config";
}
}
public string GetDataDirectory(){
EnvDTE.Project project=GetCurrentProject();
if (project != null)
{
return System.IO.Path.GetDirectoryName(project.FileName)+"\\App_Data\\";
}
else
{
return ProjectPathDefault+"App_Data\\";
}
}
...
然后使用VS外部工具功能建立一个T4工具(工具 - >外部工具):
设置这些属性:
Then use the VS External Tools feature to set up a T4 tool (Tools->External Tools): Set these properties:
- 标题: T4
- 命令: C:\\ Program Files文件\\ Common Files文件\\微软
共享\\ TextTemplating \\ 1.2 \\ TextTransform.exe - 参数: $(PROJECTDIR)\\型号\\ Classes.tt
- 初始目录: $(PROJECTDIR)
- 使用输出窗口和提示参数应进行检查。
- Title: T4
- Command: C:\Program Files\Common Files\Microsoft Shared\TextTemplating\1.2\TextTransform.exe
- Arguments: $(ProjectDir)\Models\Classes.tt
- Initial directory: $(ProjectDir)
- Use Output window and Prompt for arguments should be checked.
点击确定,然后执行从工具 - 新创建的工具>外部工具菜单中。
Click Ok and then execute the newly created tool from the Tools->External Tools menu.
这篇关于在Visual Web Developer中前preSS亚音速ASP.NET MVC示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!