Beispiel #1
0
        private void VisitAssemblyGroup(
            InstrumentationContext context,
            InstrumentationResult result,
            IEnumerable <FileInfo> groupFiles)
        {
            var firstAssemblyFile = groupFiles.First();

            var instrumentedAssembly = _assemblyInstrumenter.InstrumentAssembly(
                context,
                firstAssemblyFile);

            if (instrumentedAssembly == null)
            {
                return;
            }

            foreach (var assemblyFile in groupFiles)
            {
                var pdbFile            = FileUtils.GetPdbFile(assemblyFile);
                var assemblyBackupFile = FileUtils.GetBackupFile(assemblyFile);
                var pdbBackupFile      = FileUtils.GetBackupFile(pdbFile);

                //Backup
                File.Copy(assemblyFile.FullName, assemblyBackupFile.FullName, true);
                File.Copy(pdbFile.FullName, pdbBackupFile.FullName, true);

                //Override assembly
                File.Copy(instrumentedAssembly.TempAssemblyFile, assemblyFile.FullName, true);
                File.Copy(instrumentedAssembly.TempPdbFile, pdbFile.FullName, true);

                //Copy instrumentation dependencies
                var assemblyDirectory = assemblyFile.Directory;

                var hitServicesPath    = Path.GetFileName(hitServicesAssembly.Location);
                var newHitServicesPath = Path.Combine(assemblyDirectory.FullName, hitServicesPath);
                if (!File.Exists(newHitServicesPath))
                {
                    File.Copy(hitServicesAssembly.Location, newHitServicesPath, true);
                    result.AddExtraAssembly(newHitServicesPath);
                }

                instrumentedAssembly.AddLocation(
                    assemblyFile.FullName,
                    assemblyBackupFile.FullName,
                    pdbFile.FullName,
                    pdbBackupFile.FullName
                    );

                var hitServicesAssemblyVersion = FileVersionInfo.GetVersionInfo(hitServicesAssembly.Location);
                foreach (var depsJsonFile in assemblyDirectory.GetFiles("*.deps.json"))
                {
                    DepsJsonUtils.PatchDepsJson(depsJsonFile, hitServicesAssemblyVersion.ProductVersion);
                }
            }

            result.AddInstrumentedAssembly(instrumentedAssembly);

            File.Delete(instrumentedAssembly.TempAssemblyFile);
            File.Delete(instrumentedAssembly.TempPdbFile);
        }
Beispiel #2
0
        private void VisitAssemblyGroup(IEnumerable <string> assemblyFiles)
        {
            var firstAssemblyFile = assemblyFiles.First();

            var instrumentedAssembly = InstrumentAssemblyIfNecessary(firstAssemblyFile);

            if (instrumentedAssembly == null)
            {
                return;
            }

            foreach (var assemblyFile in assemblyFiles)
            {
                var pdbFile            = GetPdbFile(assemblyFile);
                var assemblyBackupFile = GetBackupFile(assemblyFile);
                var pdbBackupFile      = GetBackupFile(pdbFile);

                //Backup
                File.Copy(assemblyFile, assemblyBackupFile, true);
                File.Copy(pdbFile, pdbBackupFile, true);

                //Override assembly
                File.Copy(instrumentedAssembly.TempAssemblyFile, assemblyFile, true);
                File.Copy(instrumentedAssembly.TempPdbFile, pdbFile, true);

                //Copy instrumentation dependencies
                var assemblyDirectory = Path.GetDirectoryName(assemblyFile);

                foreach (var dependencyPath in instrumentationDependencies)
                {
                    var dependencyAssemblyName = Path.GetFileName(dependencyPath);
                    var newDependencyPath      = Path.Combine(assemblyDirectory, dependencyAssemblyName);
                    File.Copy(dependencyPath, newDependencyPath, true);
                    result.AddExtraAssembly(newDependencyPath);
                }

                instrumentedAssembly.AddLocation(
                    Path.GetFullPath(assemblyFile),
                    Path.GetFullPath(assemblyBackupFile),
                    Path.GetFullPath(pdbFile),
                    Path.GetFullPath(pdbBackupFile)
                    );

                foreach (var depsJsonFile in Directory.GetFiles(assemblyDirectory, "*.deps.json"))
                {
                    DepsJsonUtils.PatchDepsJson(depsJsonFile);
                }
            }

            result.AddInstrumentedAssembly(instrumentedAssembly);

            File.Delete(instrumentedAssembly.TempAssemblyFile);
            File.Delete(instrumentedAssembly.TempPdbFile);
        }
        public void ShouldPatchDepsJson()
        {
            var fileName        = @"c:\source\deps.json";
            var originalContent = GetOriginalDepsJsonContent();

            _mockFileSystem.AddFile(fileName, new MockFileData(originalContent));

            var expectedResult = GetPatchedDepsJsonContent();

            _sut.PatchDepsJson(_mockFileSystem.FileInfo.FromFileName(fileName), "1.0.0");

            var result = _mockFileSystem.GetFile(fileName).TextContents;

            result.ToOSLineEnding().Should().Be(expectedResult.ToOSLineEnding());
        }
Beispiel #4
0
        /// <summary>
        /// An assembly group is a set of assemblies that are identical (the same file hash). This method makes sure we only instrument the first assembly in the group, to avoid unnecessary overhead.
        /// </summary>
        private void VisitAssemblyGroup(
            IInstrumentationContext context,
            InstrumentationResult result,
            IReadOnlyCollection <IFileInfo> assemblyFiles)
        {
            using (_logger.BeginScope("Checking assembly files {assemblies}", assemblyFiles.Select(f => f.FullName)))
            {
                var instrumentedAssembly = _assemblyInstrumenter.InstrumentAssemblyFile(
                    context,
                    assemblyFiles.First());

                if (instrumentedAssembly == null)
                {
                    return;
                }

                _logger.LogTrace("Temporary assembly file: {tempAssemblyFile}", instrumentedAssembly.TempAssemblyFile);
                _logger.LogTrace("Temporary PDB file: {tempPdbFile}", instrumentedAssembly.TempPdbFile);

                foreach (var assemblyFile in assemblyFiles)
                {
                    _logger.LogDebug("Instrumenting assembly file {assemblyFile}", assemblyFile.FullName);

                    if (_loadedAssemblyFiles.Contains(assemblyFile.FullName))
                    {
                        _logger.LogInformation("Skipping loaded assembly {assemblyFile}", assemblyFile.FullName);
                        continue;
                    }

                    var pdbFile            = FileUtils.GetPdbFile(assemblyFile);
                    var assemblyBackupFile = FileUtils.GetBackupFile(assemblyFile);
                    var pdbBackupFile      = FileUtils.GetBackupFile(pdbFile);

                    _logger.LogTrace("PDB file: {pdbFileName}", pdbFile.FullName);
                    _logger.LogTrace("Assembly backup file: {assemblyBackupFileName}", assemblyBackupFile.FullName);
                    _logger.LogTrace("PDB backup file: {pdbBackupFileName}", pdbBackupFile.FullName);

                    //Backup
                    _fileSystem.File.Copy(assemblyFile.FullName, assemblyBackupFile.FullName, true);
                    _fileSystem.File.Copy(pdbFile.FullName, pdbBackupFile.FullName, true);

                    //Override assembly
                    _fileSystem.File.Copy(instrumentedAssembly.TempAssemblyFile, assemblyFile.FullName, true);
                    _fileSystem.File.Copy(instrumentedAssembly.TempPdbFile, pdbFile.FullName, true);

                    //Copy instrumentation dependencies
                    var assemblyDirectory = assemblyFile.Directory;
                    _logger.LogTrace("Assembly directory: {assemblyDirectory}", assemblyDirectory.FullName);

                    var hitServicesPath    = Path.GetFileName(hitServicesAssembly.Location);
                    var newHitServicesPath = Path.Combine(assemblyDirectory.FullName, hitServicesPath);
                    _fileSystem.File.Copy(hitServicesAssembly.Location, newHitServicesPath, true);
                    result.AddExtraAssembly(newHitServicesPath);

                    instrumentedAssembly.AddLocation(
                        assemblyFile.FullName,
                        assemblyBackupFile.FullName,
                        pdbFile.FullName,
                        pdbBackupFile.FullName
                        );

                    var hitServicesAssemblyVersion = FileVersionInfo.GetVersionInfo(hitServicesAssembly.Location);
                    foreach (var depsJsonFile in assemblyDirectory.GetFiles("*.deps.json"))
                    {
                        _depsJsonUtils.PatchDepsJson(depsJsonFile, hitServicesAssemblyVersion.ProductVersion);
                    }
                }

                result.AddInstrumentedAssembly(instrumentedAssembly);

                _fileSystem.File.Delete(instrumentedAssembly.TempAssemblyFile);
                _fileSystem.File.Delete(instrumentedAssembly.TempPdbFile);
            }
        }
Beispiel #5
0
        private void VisitAssemblyGroup(
            InstrumentationContext context,
            InstrumentationResult result,
            IEnumerable <FileInfo> assemblyFiles)
        {
            using (_logger.BeginScope("Checking assembly files {assemblies}", assemblyFiles.Select(f => f.FullName), LogLevel.Information))
            {
                var instrumentedAssembly = _assemblyInstrumenter.InstrumentAssemblyFile(
                    context,
                    assemblyFiles.First());

                if (instrumentedAssembly == null)
                {
                    return;
                }

                foreach (var assemblyFile in assemblyFiles)
                {
                    if (_loadedAssemblyFiles.Contains(assemblyFile.FullName))
                    {
                        _logger.LogInformation("Skipping loaded assembly {assemblyFile}", assemblyFile.FullName);
                        continue;
                    }

                    var pdbFile            = FileUtils.GetPdbFile(assemblyFile);
                    var assemblyBackupFile = FileUtils.GetBackupFile(assemblyFile);
                    var pdbBackupFile      = FileUtils.GetBackupFile(pdbFile);

                    //Backup
                    File.Copy(assemblyFile.FullName, assemblyBackupFile.FullName, true);
                    File.Copy(pdbFile.FullName, pdbBackupFile.FullName, true);

                    //Override assembly
                    File.Copy(instrumentedAssembly.TempAssemblyFile, assemblyFile.FullName, true);
                    File.Copy(instrumentedAssembly.TempPdbFile, pdbFile.FullName, true);

                    //Copy instrumentation dependencies
                    var assemblyDirectory = assemblyFile.Directory;

                    var hitServicesPath    = Path.GetFileName(hitServicesAssembly.Location);
                    var newHitServicesPath = Path.Combine(assemblyDirectory.FullName, hitServicesPath);
                    File.Copy(hitServicesAssembly.Location, newHitServicesPath, true);
                    result.AddExtraAssembly(newHitServicesPath);

                    instrumentedAssembly.AddLocation(
                        assemblyFile.FullName,
                        assemblyBackupFile.FullName,
                        pdbFile.FullName,
                        pdbBackupFile.FullName
                        );

                    var hitServicesAssemblyVersion = FileVersionInfo.GetVersionInfo(hitServicesAssembly.Location);
                    foreach (var depsJsonFile in assemblyDirectory.GetFiles("*.deps.json"))
                    {
                        DepsJsonUtils.PatchDepsJson(depsJsonFile, hitServicesAssemblyVersion.ProductVersion);
                    }
                }

                result.AddInstrumentedAssembly(instrumentedAssembly);

                File.Delete(instrumentedAssembly.TempAssemblyFile);
                File.Delete(instrumentedAssembly.TempPdbFile);
            }
        }