protected async Task <AnalyzerResult> DesignTimeBuild() { using (var operation = _log.OnEnterAndConfirmOnExit()) { AnalyzerResult result; var csProj = this.GetProjectFile(); var logWriter = new StringWriter(); using (await FileLock.TryCreateAsync(Directory)) { var manager = new AnalyzerManager(new AnalyzerManagerOptions { LogWriter = logWriter }); var analyzer = manager.GetProject(csProj.FullName); analyzer.AddBinaryLogger(Path.Combine(Directory.FullName, DesignTimeBuildBinlogFileName)); var languageVersion = csProj.SuggestedLanguageVersion(); analyzer.SetGlobalProperty("langVersion", languageVersion); result = analyzer.Build().Results.First(); } DesignTimeBuildResult = result; LastDesignTimeBuild = Clock.Current.Now(); if (result.Succeeded == false) { var logData = logWriter.ToString(); File.WriteAllText( LastBuildErrorLogFile.FullName, string.Join(Environment.NewLine, "Design Time Build Error", logData)); } else if (LastBuildErrorLogFile.Exists) { LastBuildErrorLogFile.Delete(); } operation.Succeed(); return(result); } }
public override async Task FullBuild() { using (var operation = Log.OnEnterAndConfirmOnExit()) { try { operation.Info("Attempting building package {name}", Name); var buildInProgress = _buildSemaphore.CurrentCount == 0; await _buildSemaphore.WaitAsync(); using (Disposable.Create(() => _buildSemaphore.Release())) { if (buildInProgress) { operation.Info("Skipping build for package {name}", Name); return; } using (await FileLock.TryCreateAsync(Directory)) { await DotnetBuild(); } } operation.Info("Workspace built"); operation.Succeed(); } catch (Exception exception) { operation.Error("Exception building workspace", exception); } var binLog = this.FindLatestBinLog(); await binLog.WaitForFileAvailable(); await LoadDesignTimeBuildFromBuildLogFile(this, binLog); } }
private static async Task LoadDesignTimeBuildFromBuildLogFile(Package package, FileSystemInfo binLog) { var projectFile = package.GetProjectFile(); if (projectFile != null && binLog.LastWriteTimeUtc >= projectFile.LastWriteTimeUtc) { AnalyzerResults results; using (await FileLock.TryCreateAsync(package.Directory)) { var manager = new AnalyzerManager(); results = manager.Analyze(binLog.FullName); } if (results.Count == 0) { throw new InvalidOperationException("The build log seems to contain no solutions or projects"); } var result = results.FirstOrDefault(p => p.ProjectFilePath == projectFile.FullName); if (result != null) { package.RoslynWorkspace = null; package.DesignTimeBuildResult = result; package.LastDesignTimeBuild = binLog.LastWriteTimeUtc; if (result.Succeeded && !binLog.Name.EndsWith(DesignTimeBuildBinlogFileName)) { package.LastSuccessfulBuildTime = binLog.LastWriteTimeUtc; if (package.DesignTimeBuildResult.TryGetWorkspace(out var ws)) { package.RoslynWorkspace = ws; } } } } }
public static async Task <bool> Create( this IHaveADirectory packageBase, IPackageInitializer initializer) { using (var operation = Logger <PackageBase> .Log.OnEnterAndConfirmOnExit()) { if (!packageBase.Directory.Exists) { operation.Info("Creating directory {directory}", packageBase.Directory); packageBase.Directory.Create(); packageBase.Directory.Refresh(); } using (await FileLock.TryCreateAsync(packageBase.Directory)) { if (!packageBase.Directory.GetFiles("*", SearchOption.AllDirectories).Where(f => !FileLock.IsLockFile(f)).Any()) { operation.Info("Initializing package using {_initializer} in {directory}", initializer, packageBase.Directory); await initializer.Initialize(packageBase.Directory); } } operation.Succeed(); return(true); } }