Exemple #1
0
        public void CanCreateCsProjectFileWithTargetFramework()
        {
            const string filePath = @"Helpers\TestProjFile.xml";

            var result = CsProjectFileReader.Read(filePath);

            // expects 'netstandard2.0' based on the test xml file
            Assert.Equal("netstandard2.0", result.TargetFramework);
        }
Exemple #2
0
        /// <summary>
        /// Gets Migration Types from a compiled project assembly
        /// </summary>
        /// <param name="fileInfo">The project file directory</param>
        /// <returns>A list of migration types</returns>
        public static List <Type> GetMigrationTypes(FileInfo fileInfo)
        {
            // get project framework
            var csProjectFile   = CsProjectFileReader.Read(fileInfo.FullName);
            var targetFramework = csProjectFile.TargetFramework;
            // there can be multiple target frameworks. split and pick first
            var framework = targetFramework.Split(';')[0];

            var projectDll = Path.Combine(
                new[]
            {
                fileInfo.DirectoryName,
                "bin",
                BuildConfiguration.Debug.ToString(),
                framework,
                fileInfo.Name.Replace(fileInfo.Extension, ".dll")
            }
                );

            return(Assembly.LoadFrom(projectDll).GetTypes()
                   .Where(x => x.IsClass && x.Namespace == "Migrations")
                   .OrderBy(x => x.Name)
                   .ToList());
        }
Exemple #3
0
        public void HandleNoProjectFileDirectory()
        {
            const string filePath = @"test\test.xml";

            Assert.Throws <DirectoryNotFoundException>(() => CsProjectFileReader.Read(filePath));
        }