public IList <ResourceDescriptor> GetResources(ICompilationProject project)
        {
            string root = PathUtility.EnsureTrailingSlash(project.ProjectDirectory);

            return(project
                   .Files.ResourceFiles
                   .Where(res => !ResxResourceProvider.IsResxResourceFile(res.Key))
                   .Select(resourceFile =>
            {
                string resourceName;
                string rootNamespace;

                if (string.IsNullOrEmpty(resourceFile.Value))
                {
                    // No logical name, so use the file name
                    resourceName = ResourcePathUtility.GetResourceName(root, resourceFile.Key);
                    rootNamespace = project.Name;
                }
                else
                {
                    resourceName = CreateCSharpManifestResourceName.EnsureResourceExtension(resourceFile.Value, resourceFile.Key);
                    rootNamespace = null;
                }

                return new ResourceDescriptor()
                {
                    Name = CreateCSharpManifestResourceName.CreateManifestName(resourceName, rootNamespace),
                    StreamFactory = () => new FileStream(resourceFile.Key, FileMode.Open, FileAccess.Read, FileShare.Read)
                };
            })
                   .ToList());
        }
示例#2
0
        // Original source: https://raw.githubusercontent.com/Microsoft/msbuild/82177a50da735cc0443ac10fa490d69368403d71/src/XMakeTasks/CreateCSharpManifestResourceName.cs

        public static string CreateManifestName(string fileName, string rootNamespace)
        {
            var name = new StringBuilder();

            // Differences from the msbuild task:
            // - we do not include the name of the first class (if any) for binary resources or source code
            // - culture info is ignored

            if (rootNamespace != null && rootNamespace.Length > 0)
            {
                name.Append(rootNamespace).Append(".");
            }

            // Replace spaces in the directory name with underscores.
            // Note that spaces in the file name itself are preserved.
            var path = MakeValidIdentifier(Path.GetDirectoryName(fileName));

            // This is different from the msbuild task: we always append extensions because otherwise,
            // the emitted resource doesn't have an extension and it is not the same as in the classic
            // C# assembly
            if (ResxResourceProvider.IsResxResourceFile(fileName))
            {
                name.Append(Path.Combine(path, Path.GetFileNameWithoutExtension(fileName)));
                name.Append(".resources");
                name.Replace(Path.DirectorySeparatorChar, '.');
                name.Replace(Path.AltDirectorySeparatorChar, '.');
            }
            else
            {
                name.Append(Path.Combine(path, Path.GetFileName(fileName)));
                name.Replace(Path.DirectorySeparatorChar, '.');
                name.Replace(Path.AltDirectorySeparatorChar, '.');
            }

            return(name.ToString());
        }