Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation failure #139

Open
chalcrow opened this issue Dec 19, 2022 · 4 comments
Open

Compilation failure #139

chalcrow opened this issue Dec 19, 2022 · 4 comments

Comments

@chalcrow
Copy link

chalcrow commented Dec 19, 2022

I'm working on a project that uses T4MV, with the latest versions of the T4MVC and T4MVCExtensions nuget packages (v4.2.4)

When I rebuild the project in VS2022, I get an error for T4MVC.cs:

A namespace cannot directly contain members such as fields, methods or statements.

T4MVC.cs only contains ErrorGeneratingOutput

I'm getting error in controllers as follows. I think this is probably because T4MVC isn't compiling:

The name 'MVC' does not exist in the current context.

When I right click T4MVC.tt and choose 'Run custom tool', I see the following errors related to T4MVC.tt.hooks.t4:

Compiling transformation: Invalid token 'this' in class, record, struct, or interface member declaration
Compiling transformation: 'GeneratedTextTransformation.GeneratedTextTransformation()' must declare a body because it is not marked abstract, extern, or partial
Compiling transformation: Method must have a return type
Compiling transformation: Identifier expected

I'm looking for ideas in how to diagnose the issue, or what may be causing the issue. I don't believe it's a namespace conflict, as in this Q&A

If I right-click T4MVC.tt and select
Debug T4 template, I get other errors.

Here's my T4MVC.tt.settings.xml file:

<?xml version="1.0" encoding="utf-8"?>
<MvcSettings>
  <!--The namespace used by some of T4MVC's generated code-->
  <T4MVCNamespace>T4MVC</T4MVCNamespace>
  <!--The prefix used for things like MVC.Dinners.Name and MVC.Dinners.Delete(Model.DinnerID)-->
  <HelpersPrefix>MVC</HelpersPrefix>
  <!--Namespaces to be referenced by the generated code-->
  <ReferencedNamespaces>
    <!--<Namespace></Namespace>-->
  </ReferencedNamespaces>
  <!--The folder under the project that contains the areas-->
  <AreasFolder>Areas</AreasFolder>
  <!--You can list folders containing portable areas here-->
  <PortableAreas>
    <!--<Area></Area>-->
  </PortableAreas>
  <!--Name of folder in your project root that follows the FeatureFolder convention (controllers and views are placed within the same folder)-->
  <!--<FeatureFolderRootArea></FeatureFolderRootArea>-->
  <!--Names of areas which follow the FeatureFolder convention (controllers and views are placed within the same folder).
Use <Area>*</Area> if you only use Areas with FeatureFolders-->
  <FeatureFolderAreas>
    <!--<Area></Area>-->
  </FeatureFolderAreas>
  <!--Choose whether you want to include an 'Areas' token when referring to areas.
e.g. Assume the Area is called Blog and the Controller is Post:
- When false use MVC.Blog.Post.etc...
- When true use MVC.Areas.Blog.Post.etc...-->
  <IncludeAreasToken>False</IncludeAreasToken>
  <!--The folder under the project that contains the controllers-->
  <ControllersFolder>Controllers</ControllersFolder>
  <!--The folder under the project that contains the views-->
  <ViewsRootFolder>Views</ViewsRootFolder>
  <!--Views in DisplayTemplates and EditorTemplates folders shouldn't be fully qualifed
as it breaks the templated helper code-->
  <NonQualifiedViewFolders>
    <ViewFolder>DisplayTemplates</ViewFolder>
    <ViewFolder>EditorTemplates</ViewFolder>
  </NonQualifiedViewFolders>
  <!--If true, the T4MVC action result interface will be generated
If false, the namespace of the interface must be referenced in the 'ReferencedNamespaces' setting-->
  <GenerateActionResultInterface>True</GenerateActionResultInterface>
  <!--If true, [new] overrides will be created for async actions on AsyncControllers
This breaks the Go To Definition function for async actions.-->
  <SupportAsyncActions>False</SupportAsyncActions>
  <!--If true, use lower case tokens in routes for the area, controller and action names-->
  <UseLowercaseRoutes>False</UseLowercaseRoutes>
  <!--The namespace that the links are generated in (e.g. "Links", as in Links.Content.nerd_jpg)-->
  <LinksNamespace>Links</LinksNamespace>
  <!--The namespace that raw URLS used for bundles are generated-->
  <AssetsNamespace>Assets</AssetsNamespace>
  <!--If true, links to static files include a query string containing the file's last change time.
This way, when the static file changes, the link changes and guarantees that the client will re-request the resource.
e.g. when true, the link looks like: "/Content/nerd.jpg?2009-09-04T12:25:48"
See http://mvccontrib.codeplex.com/workitem/7163 for potential issues with this feature-->
  <AddTimestampToStaticLinks>False</AddTimestampToStaticLinks>
  <!--Folders containing static files for which links are generated (e.g. Links.Scripts.Map_js)-->
  <StaticFilesFolders>
    <FileFolder>Scripts</FileFolder>
    <FileFolder>Content</FileFolder>
  </StaticFilesFolders>
  <!--If true, static file helpers are generated for all view folders. See https://t4mvc.codeplex.com/discussions/445358-->
  <AddAllViewsFoldersToStaticFilesFolders>False</AddAllViewsFoldersToStaticFilesFolders>
  <!--Static files to exclude from the generated links-->
  <ExcludedStaticFileExtensions>
    <Extension>.cs</Extension>
    <Extension>.cshtml</Extension>
    <Extension>.aspx</Extension>
    <Extension>.ascx</Extension>
  </ExcludedStaticFileExtensions>
  <!--Files to exclude from the generated views-->
  <ExcludedViewExtensions>
    <Extension>.cs</Extension>
    <Extension>.master</Extension>
    <Extension>.js</Extension>
    <Extension>.css</Extension>
  </ExcludedViewExtensions>
  <!--When creating links with T4MVC, it can force them to HTTPS if the action method you are linking to requires Http.-->
  <AttributeIndicatingHttps>System.Web.Mvc.RequireHttpsAttribute</AttributeIndicatingHttps>
  <GenerateSecureLinksInDebugMode>False</GenerateSecureLinksInDebugMode>
  <!--Set this to false to omit the generation of parameters for action methods.-->
  <GenerateParamsForActionMethods>True</GenerateParamsForActionMethods>
  <!--Set this to true to omit the generation of parameters for action methods as constants.  Choose this or GenerateParamsForActionMethods.-->
  <GenerateParamsAsConstantsForActionMethods>False</GenerateParamsAsConstantsForActionMethods>
  <!--The suffix added to action method names for the property containing the parameters, for example ImportParams
for the Import action method.-->
  <ParamsPropertySuffix>Params</ParamsPropertySuffix>
  <!--create explicit HtmlHelpers for rendering partials-->
  <ExplicitHtmlHelpersForPartials>False</ExplicitHtmlHelpersForPartials>
  <ExplicitHtmlHelpersForPartialsFormat>Render{0}</ExplicitHtmlHelpersForPartialsFormat>
  <!--If true,the template output will be split into multiple files.-->
  <SplitIntoMultipleFiles>True</SplitIntoMultipleFiles>
</MvcSettings>
@davidebbo
Copy link
Contributor

I'm away from a PC for a week, so I can't help much right now. Suggestions:

  • Paste the errors that you're getting as text, not screenshot, to make it easier to search for the text
  • Do you see this if you try T4MVC in a brand new project?
  • Long shot, but maybe you have an unwanted blank line at the end of the t4 file, as in this (very old) question? Your errors look similar, but may very well be unrelated

@chalcrow
Copy link
Author

Thanks @davidebbo I edited the question to use text for the errors. It's not the blank line or the line ending. I tried updating to only a Windows line ending (CRLF i.e. \r\n), and I get the same errors.

@chalcrow
Copy link
Author

chalcrow commented Dec 19, 2022

@davidebbo you were on the right lines with the long shot thanks. Compilation works for the same code commit, for another developer using the same Visual Studio and T4MVC versions. It doesn't appear to be a line ending issue, it looks like another config issue local to my environment.

I'm using Windows, and I tried removing all trailing characters at the end of the .tt file. I also tried inserting only CRLF as the only trailing characters. I also tried this, to renormalize all of the line endings across my local repo to CRLF:

git config --global core.autocrlf true

git add --renormalize .

I tried the 'Run custom tool' option again via Visual Studio, but got exactly the same error messages.

I've updated the StackOverflow post on the issue - https://stackoverflow.com/questions/74845423/why-am-i-getting-the-error-errorgeneratingoutput-when-compiling

@davidebbo
Copy link
Contributor

Sorry, I'm not sure what could be going on. I'd suggest trying to minimize. e.g. does 'Run custom tool' work for you if you remove almost everything from the template file? If you see the same problem with a minimal template, then at least we know it's a T4 issue and not T4MVC specific.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants