OmniSharp / generator-aspnet

yo generator for ASP.NET Core
877 stars 168 forks source link

Migrating the project.json file to the new .csproj breaks the Sub Generators #849

Closed k1l3s closed 5 years ago

k1l3s commented 7 years ago

Short issue description

Migrating the project.json to the new .csproj format throws an error using the subgenerators.

Expected behavior

"yo aspnet:class Filename" should create the expected class

Actual behavior

"yo aspnet:class Filename" actually throws an "events.js:160 throw er; // Unhandled 'error' event"

Steps to reproduce the behavior

-Install Asp.net core 1.1. -Use the aspnet-generator to create a ASP.net basic template. -Run the "dotnet migrate" command to migrate to .csproj. -Run "dotnet restore" -Run "yo aspnet:class NewClass"

That should throw the error


OS version (Win/Mac/*Nix?)

Windows 10

NodeJS version

node --version

v6.6.0

Yeoman version

yo --version

1.8.5

Generator version

NPM 3.*:

npm list -g generator-aspnet

generator-aspnet@0.2.5

Notes

I think the error is caused by the file configuration.js. This file is made to find up a hardcoded 'project.json' inside the project, how this file does not exist anymore the baseDirectory var should be null. (Maybe could be done to support both cdproj and json???)


  // Get the namespace relative to the cwd
  getNamespace: function(fs) {
    'use strict';

    var baseNamespace = getBaseNamespace(fs);
    var cwd = process.cwd();
    var baseDirectory = path.resolve(path.dirname(this.getProjectCsprojPath()));
    var relativePath = path.relative(baseDirectory, cwd);
    if (relativePath) {
      return [baseNamespace].concat(relativePath.split(path.sep)).join('.');
    }

    return baseNamespace;
  },
  getProjectJsonPath: function() {
    'use strict';

    return findup('project.json');
  },
  getProjectJson: function(fs) {
    'use strict';

    var path = module.exports.getProjectJsonPath();
    if (!path) {
      return {};
    }

    return fs.readJSON(path, {});
  },
  getGlobalJsonPath: function() {
    'use strict';

    return findup('global.json');
  },
  getGlobalJson: function(fs) {
    'use strict';

    var path = module.exports.getGlobalJsonPath(path);
    if (!path) {
      return {};
    }

    return fs.readJSON(path, {});
  },
};
peterblazejewicz commented 7 years ago

That's unlikely to be fixed before (if at all) migration is done this one: https://github.com/OmniSharp/generator-aspnet/issues/846

sayedihashimi commented 5 years ago

We are shutting this repo down, it's been replaced with dotnet new.