Exemplo n.º 1
0
        public ProjectService(Project project, PackageService packageService, TemplateService templateService)
        {
            // If the selected item on the Solution Explorer is a Solution Folder, some of the properties of 'project'
            // will be null or empty. Examples are CodeModel and FullName both used below.

            _project = project;
            _defaultExtensionByProjectType = string.Empty;

            switch (_project.CodeModel?.Language)
            {
            case CodeModelLanguageConstants.vsCMLanguageCSharp:
                _defaultExtensionByProjectType = ".cs";
                break;

            case CodeModelLanguageConstants.vsCMLanguageVB:
                _defaultExtensionByProjectType = ".vb";
                break;
            }

            _packageService  = packageService;
            _templateService = templateService;

            bool wasRetreived = this.TryGetProperty("FullPath", out Property prop)
                                // MFC projects don't have FullPath, and there seems to be no way to query existence
                                || this.TryGetProperty("ProjectDirectory", out prop) ||
                                this.TryGetProperty("ProjectPath", out prop);

            if (wasRetreived)
            {
                _projectRoot = prop.Value.ToString();
            }
            else
            {
                _projectRoot = Path.GetDirectoryName(_project.DTE.Solution.FullName);
            }

            if (_projectRoot[_projectRoot.Length - 1] == Path.DirectorySeparatorChar || _projectRoot[_projectRoot.Length - 1] == Path.AltDirectorySeparatorChar)
            {
                _projectRoot = _projectRoot.Substring(0, _projectRoot.Length - 1);
            }
        }
Exemplo n.º 2
0
 public NewFileBuilder(Package package)
 {
     _packageService   = new PackageService(package);
     _templateSerivice = new TemplateService(_packageService);
 }