Exemplo n.º 1
0
        public override async Task AddFileToProjectAsync(string filePath)
        {
            await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync();

            EnvDTEProjectUtility.EnsureCheckedOutIfExists(_vsProjectAdapter.Project, await _vsProjectAdapter.GetProjectDirectoryAsync(), filePath);

            var isFileExistsInProject = await EnvDTEProjectUtility.ContainsFileAsync(_vsProjectAdapter.Project, filePath);

            if (!isFileExistsInProject)
            {
                await AddProjectItemAsync(filePath);
            }
        }
Exemplo n.º 2
0
        private Task AddFileCoreAsync(string path, Action addFile)
        {
            // Do not try to add file to project, if the path is null or empty.
            if (string.IsNullOrEmpty(path))
            {
                return(Task.FromResult(false));
            }

            var fileExistsInProject = FileExistsInProject(path);

            // If the file exists on disk but not in the project then skip it.
            // One exception is the 'packages.config' file, in which case we want to include
            // it into the project.
            // Other exceptions are 'web.config' and 'app.config'
            var fileName         = Path.GetFileName(path);
            var lockFileFullPath = PackagesConfigLockFileUtility.GetPackagesLockFilePath(ProjectFullPath, GetPropertyValue("NuGetLockFilePath")?.ToString(), ProjectName);

            if (File.Exists(Path.Combine(ProjectFullPath, path)) &&
                !fileExistsInProject &&
                !fileName.Equals(ProjectManagement.Constants.PackageReferenceFile) &&
                !fileName.Equals("packages." + ProjectName + ".config") &&
                !fileName.Equals(EnvDTEProjectInfoUtility.WebConfig) &&
                !fileName.Equals(EnvDTEProjectInfoUtility.AppConfig) &&
                !fileName.Equals(Path.GetFileName(lockFileFullPath))
                )
            {
                NuGetProjectContext.Log(ProjectManagement.MessageLevel.Warning, Strings.Warning_FileAlreadyExists, path);
            }
            else
            {
                EnvDTEProjectUtility.EnsureCheckedOutIfExists(VsProjectAdapter.Project, ProjectFullPath, path);
                addFile();
                if (!fileExistsInProject)
                {
                    return(AddFileToProjectAsync(path));
                }
            }

            return(Task.FromResult(false));
        }
Exemplo n.º 3
0
 private void EnsureCheckedOutIfExists(string path)
 {
     EnvDTEProjectUtility.EnsureCheckedOutIfExists(EnvDTEProject, ProjectFullPath, path);
 }