public PackageItem(ITaskItem item)
        {
            OriginalItem  = item;
            SourcePath    = item.GetMetadata("FullPath");
            SourceProject = GetMetadata("MSBuildSourceProjectFile");
            string value = GetMetadata("TargetFramework");

            if (!String.IsNullOrWhiteSpace(value))
            {
                TargetFramework = NuGetFramework.Parse(value);
            }
            TargetPath           = item.GetMetadata(nameof(TargetPath));
            AdditionalProperties = GetMetadata(nameof(AdditionalProperties));
            UndefineProperties   = GetMetadata(nameof(UndefineProperties));
            HarvestedFrom        = GetMetadata(nameof(HarvestedFrom));
            Package        = GetMetadata("PackageId");
            PackageVersion = GetMetadata("PackageVersion");
            IsDll          = Path.GetExtension(SourcePath).Equals(".dll", StringComparison.OrdinalIgnoreCase);
            IsPlaceholder  = NuGetAssetResolver.IsPlaceholder(SourcePath);
            IsRef          = TargetPath.StartsWith("ref/", StringComparison.OrdinalIgnoreCase);

            // determine if we need to append filename to TargetPath
            // see https://docs.nuget.org/create/nuspec-reference#specifying-files-to-include-in-the-package
            // SourcePath specifies file and target specifies file - do nothing
            // SourcePath specifies file and Target specifies directory - copy filename
            // SourcePath specifies wildcard files - copy wildcard
            // SourcePath specifies recursive wildcard - do not allow, recursive directory may impact asset selection
            //   we don't want to attempt to expand the wildcard since the build may not yet be complete.

            if (SourcePath.Contains("**"))
            {
                throw new ArgumentException($"Recursive wildcards \"**\" are not permitted in source paths for packages: {SourcePath}.  Recursive directory may impact asset selection and we don't want to attempt to expand the wildcard since the build may not yet be complete.");
            }

            string sourceFile = Path.GetFileName(SourcePath);

            if (!Path.GetExtension(TargetPath).Equals(Path.GetExtension(sourceFile), StringComparison.OrdinalIgnoreCase) ||
                sourceFile.Contains("*"))
            {
                TargetPath = Path.Combine(TargetPath, sourceFile);
            }

            // standardize to /
            TargetPath = TargetPath.Replace('\\', '/');

            int dirLength = TargetPath.LastIndexOf('/');

            TargetDirectory = (dirLength > 0) ? TargetPath.Substring(0, dirLength) : String.Empty;
        }
Exemple #2
0
        void GenerateCode()
        {
            //Create the target directory if required
            Directory.CreateDirectory(Path.GetDirectoryName(OutputFile));

            var ccu = new CodeCompileUnit();

            ccu.AssemblyCustomAttributes.Add(
                new CodeAttributeDeclaration(new CodeTypeReference($"global::{typeof(XamlResourceIdAttribute).FullName}"),
                                             new CodeAttributeArgument(new CodePrimitiveExpression(ResourceId)),
                                             new CodeAttributeArgument(new CodePrimitiveExpression(TargetPath.Replace('\\', '/'))),                                             //use forward slashes, paths are uris-like
                                             new CodeAttributeArgument(RootType == null ? (CodeExpression) new CodePrimitiveExpression(null) : new CodeTypeOfExpression($"global::{RootClrNamespace}.{RootType}"))
                                             ));
            if (XamlResourceIdOnly)
            {
                goto writeAndExit;
            }

            if (RootType == null)
            {
                throw new Exception("Something went wrong while executing XamlG");
            }

            var declNs = new CodeNamespace(RootClrNamespace);

            ccu.Namespaces.Add(declNs);

            var declType = new CodeTypeDeclaration(RootType)
            {
                IsPartial        = true,
                CustomAttributes =
                {
                    new CodeAttributeDeclaration(new CodeTypeReference($"global::{typeof(XamlFilePathAttribute).FullName}"),
                                                 new CodeAttributeArgument(new CodePrimitiveExpression(XamlFile))),
                }
            };

            if (AddXamlCompilationAttribute)
            {
                declType.CustomAttributes.Add(
                    new CodeAttributeDeclaration(new CodeTypeReference($"global::{typeof(XamlCompilationAttribute).FullName}"),
                                                 new CodeAttributeArgument(new CodeSnippetExpression($"global::{typeof(XamlCompilationOptions).FullName}.Compile"))));
            }
            if (HideFromIntellisense)
            {
                declType.CustomAttributes.Add(
                    new CodeAttributeDeclaration(new CodeTypeReference($"global::{typeof(System.ComponentModel.EditorBrowsableAttribute).FullName}"),
                                                 new CodeAttributeArgument(new CodeSnippetExpression($"global::{typeof(System.ComponentModel.EditorBrowsableState).FullName}.{nameof(System.ComponentModel.EditorBrowsableState.Never)}"))));
            }

            declType.BaseTypes.Add(BaseType);

            declNs.Types.Add(declType);

            //Create a default ctor calling InitializeComponent
            if (GenerateDefaultCtor)
            {
                var ctor = new CodeConstructor {
                    Attributes       = MemberAttributes.Public,
                    CustomAttributes = { GeneratedCodeAttrDecl },
                    Statements       =
                    {
                        new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "InitializeComponent")
                    }
                };

                declType.Members.Add(ctor);
            }

            //Create InitializeComponent()
            var initcomp = new CodeMemberMethod {
                Name             = "InitializeComponent",
                CustomAttributes = { GeneratedCodeAttrDecl }
            };

            declType.Members.Add(initcomp);

            //Create and initialize fields
            initcomp.Statements.Add(new CodeMethodInvokeExpression(
                                        new CodeTypeReferenceExpression(new CodeTypeReference($"global::{typeof(Extensions).FullName}")),
                                        "LoadFromXaml", new CodeThisReferenceExpression(), new CodeTypeOfExpression(declType.Name)));

            foreach (var namedField in NamedFields)
            {
                declType.Members.Add(namedField);

                var find_invoke = new CodeMethodInvokeExpression(
                    new CodeMethodReferenceExpression(
                        new CodeTypeReferenceExpression(new CodeTypeReference($"global::{typeof(NameScopeExtensions).FullName}")),
                        "FindByName", namedField.Type),
                    new CodeThisReferenceExpression(), new CodePrimitiveExpression(namedField.Name));

                CodeAssignStatement assign = new CodeAssignStatement(
                    new CodeVariableReferenceExpression(namedField.Name), find_invoke);

                initcomp.Statements.Add(assign);
            }

writeAndExit:
            //write the result
            using (var writer = new StreamWriter(OutputFile))
                Provider.GenerateCodeFromCompileUnit(ccu, writer, new CodeGeneratorOptions());
        }
        void GenerateCode()
        {
            //Create the target directory if required
            Directory.CreateDirectory(Path.GetDirectoryName(OutputFile));

            var ccu = new CodeCompileUnit();

            ccu.AssemblyCustomAttributes.Add(
                new CodeAttributeDeclaration(new CodeTypeReference($"global::{typeof(XamlResourceIdAttribute).FullName}"),
                                             new CodeAttributeArgument(new CodePrimitiveExpression(ResourceId)),
                                             new CodeAttributeArgument(new CodePrimitiveExpression(TargetPath.Replace('\\', '/'))),
                                             new CodeAttributeArgument(new CodePrimitiveExpression(null))
                                             ));

            //write the result
            using (var writer = new StreamWriter(OutputFile))
                Provider.GenerateCodeFromCompileUnit(ccu, writer, new CodeGeneratorOptions());
        }
Exemple #4
0
        void GenerateCode(string outFilePath)
        {
            //Create the target directory if required
            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(outFilePath));

            var ccu = new CodeCompileUnit();

            ccu.AssemblyCustomAttributes.Add(
                new CodeAttributeDeclaration(new CodeTypeReference($"global::{typeof(XamlResourceIdAttribute).FullName}"),
                                             new CodeAttributeArgument(new CodePrimitiveExpression(ResourceId)),
                                             new CodeAttributeArgument(new CodePrimitiveExpression(TargetPath.Replace('\\', '/'))), //use forward slashes, paths are uris-like
                                             new CodeAttributeArgument(RootType == null ? (CodeExpression) new CodePrimitiveExpression(null) : new CodeTypeOfExpression($"global::{RootClrNamespace}.{RootType}"))
                                             ));
            if (XamlResourceIdOnly)
            {
                goto writeAndExit;
            }

            if (RootType == null)
            {
                throw new Exception("Something went wrong while executing XamlG");
            }

            var declNs = new CodeNamespace(RootClrNamespace);

            ccu.Namespaces.Add(declNs);

            var declType = new CodeTypeDeclaration(RootType)
            {
                IsPartial        = true,
                TypeAttributes   = GetTypeAttributes(classModifier),
                CustomAttributes =
                {
                    new CodeAttributeDeclaration(new CodeTypeReference(NUIXamlCTask.xamlNameSpace + ".XamlFilePathAttribute"),
                                                 new CodeAttributeArgument(new CodePrimitiveExpression(XamlFile))),
                }
            };

            if (AddXamlCompilationAttribute)
            {
                declType.CustomAttributes.Add(
                    new CodeAttributeDeclaration(new CodeTypeReference(NUIXamlCTask.xamlNameSpace + ".XamlCompilationAttribute"),
                                                 new CodeAttributeArgument(new CodeSnippetExpression($"global::{typeof(XamlCompilationOptions).FullName}.Compile"))));
            }
            if (HideFromIntellisense)
            {
                declType.CustomAttributes.Add(
                    new CodeAttributeDeclaration(new CodeTypeReference($"global::{typeof(System.ComponentModel.EditorBrowsableAttribute).FullName}"),
                                                 new CodeAttributeArgument(new CodeSnippetExpression($"global::{typeof(System.ComponentModel.EditorBrowsableState).FullName}.{nameof(System.ComponentModel.EditorBrowsableState.Never)}"))));
            }

            declType.BaseTypes.Add(BaseType);

            declNs.Types.Add(declType);

            //Create a default ctor calling InitializeComponent
            if (GenerateDefaultCtor)
            {
                var ctor = new CodeConstructor {
                    Attributes       = MemberAttributes.Public,
                    CustomAttributes = { GeneratedCodeAttrDecl },
                    Statements       =
                    {
                        new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "InitializeComponent")
                    }
                };

                declType.Members.Add(ctor);
            }

            //Create InitializeComponent()
            var initcomp = new CodeMemberMethod {
                Name             = "InitializeComponent",
                CustomAttributes = { GeneratedCodeAttrDecl }
            };

            declType.Members.Add(initcomp);

            //Create and initialize fields

            if (0 == XamlOptimization)
            {
                initcomp.Statements.Add(new CodeMethodInvokeExpression(
                                            new CodeTypeReferenceExpression(new CodeTypeReference($"global::{typeof(Extensions).FullName}")),
                                            "LoadFromXaml", new CodeThisReferenceExpression(), new CodeTypeOfExpression(declType.Name)));

                var exitXamlComp = new CodeMemberMethod()
                {
                    Name             = "ExitXaml",
                    CustomAttributes = { GeneratedCodeAttrDecl },
                    Attributes       = MemberAttributes.Assembly | MemberAttributes.Final
                };
                declType.Members.Add(exitXamlComp);
            }
            else
            {
                var loadExaml_invoke = new CodeMethodInvokeExpression(
                    new CodeTypeReferenceExpression(new CodeTypeReference($"global::Tizen.NUI.EXaml.EXamlExtensions")),
                    "LoadFromEXamlByRelativePath", new CodeThisReferenceExpression(),
                    new CodeMethodInvokeExpression()
                {
                    Method = new CodeMethodReferenceExpression()
                    {
                        MethodName = "GetEXamlPath"
                    }
                });

                CodeAssignStatement assignEXamlObject = new CodeAssignStatement(
                    new CodeVariableReferenceExpression("eXamlData"), loadExaml_invoke);

                initcomp.Statements.Add(assignEXamlObject);
            }

            foreach (var namedField in NamedFields)
            {
                if (namedField.Type.BaseType.Contains("-"))
                {
                    namedField.Type.BaseType = namedField.Type.BaseType.Replace("-", ".");
                }
                declType.Members.Add(namedField);

                var find_invoke = new CodeMethodInvokeExpression(
                    new CodeMethodReferenceExpression(
                        new CodeTypeReferenceExpression(new CodeTypeReference($"global::Tizen.NUI.Binding.NameScopeExtensions")),
                        "FindByName", namedField.Type),
                    new CodeThisReferenceExpression(), new CodePrimitiveExpression(namedField.Name));

                CodeAssignStatement assign = new CodeAssignStatement(
                    new CodeVariableReferenceExpression(namedField.Name), find_invoke);

                initcomp.Statements.Add(assign);
            }

            if (0 != XamlOptimization)
            {
                declType.Members.Add(new CodeMemberField
                {
                    Name             = "eXamlData",
                    Type             = new CodeTypeReference("System.Object"),
                    Attributes       = MemberAttributes.Private,
                    CustomAttributes = { GeneratedCodeAttrDecl }
                });

                var getEXamlPathcomp = new CodeMemberMethod()
                {
                    Name             = "GetEXamlPath",
                    ReturnType       = new CodeTypeReference(typeof(string)),
                    CustomAttributes = { GeneratedCodeAttrDecl }
                };

                getEXamlPathcomp.Statements.Add(new CodeMethodReturnStatement(new CodeDefaultValueExpression(new CodeTypeReference(typeof(string)))));

                declType.Members.Add(getEXamlPathcomp);

                GenerateMethodExitXaml(declType);
            }
writeAndExit:
            //write the result
            using (var writer = new StreamWriter(outFilePath))
                Provider.GenerateCodeFromCompileUnit(ccu, writer, new CodeGeneratorOptions());
        }