public void Test_ManifestResourceName_StaticPrefix() { ResourceFileSet fileset = new ResourceFileSet(); fileset.BaseDirectory = TempDirectory; fileset.Prefix = @"Root.MyProj.Howdy"; string actualName = fileset.GetManifestResourceName(Path.Combine( fileset.BaseDirectory.FullName, "mydir" + Path.DirectorySeparatorChar + "file.txt")); Assert.AreEqual(fileset.Prefix + ".file.txt", actualName, "Incorrect manifest resource name."); fileset.BaseDirectory = new DirectoryInfo(TempDirName + Path.DirectorySeparatorChar); actualName = fileset.GetManifestResourceName(Path.Combine( fileset.BaseDirectory.FullName, "mydir" + Path.DirectorySeparatorChar + "file.txt")); Assert.AreEqual(fileset.Prefix + ".file.txt", actualName, "Incorrect manifest resource name."); fileset.BaseDirectory = new DirectoryInfo(TempDirName + Path.DirectorySeparatorChar); actualName = fileset.GetManifestResourceName(Path.Combine( fileset.BaseDirectory.FullName, "file.txt")); Assert.AreEqual(fileset.Prefix + ".file.txt", actualName, "Incorrect manifest resource name."); // resource with a different logical path fileset.BaseDirectory = new DirectoryInfo(TempDirName + Path.DirectorySeparatorChar); actualName = fileset.GetManifestResourceName(Path.Combine( fileset.BaseDirectory.FullName, "file.txt"), Path.Combine( fileset.BaseDirectory.FullName, "test" + Path.DirectorySeparatorChar + "new.txt")); Assert.AreEqual(fileset.Prefix + ".file.txt", actualName, "Incorrect manifest resource name."); }
/// <summary> /// Adds a <see cref="ResourceFileSet"/> to the end of the collection. /// </summary> /// <param name="item">The <see cref="ResourceFileSet"/> to be added to the end of the collection.</param> /// <returns>The position into which the new element was inserted.</returns> public int Add(ResourceFileSet item) { return base.List.Add(item); }
/// <summary> /// Initializes a new instance of the <see cref="ResourceFileSetCollection"/> class /// with the specified array of <see cref="ResourceFileSet"/> instances. /// </summary> public ResourceFileSetCollection(ResourceFileSet[] value) { AddRange(value); }
/// <summary> /// Removes a member from the collection. /// </summary> /// <param name="item">The <see cref="ResourceFileSet"/> to remove from the collection.</param> public void Remove(ResourceFileSet item) { base.List.Remove(item); }
/// <summary> /// Inserts a <see cref="ResourceFileSet"/> into the collection at the specified index. /// </summary> /// <param name="index">The zero-based index at which <paramref name="item"/> should be inserted.</param> /// <param name="item">The <see cref="ResourceFileSet"/> to insert.</param> public void Insert(int index, ResourceFileSet item) { base.List.Insert(index, item); }
public void Test_ManifestResourceName_Resx_DynamicPrefix() { CscTask cscTask = new CscTask(); cscTask.Project = CreateEmptyProject(); ResourceFileSet resources = new ResourceFileSet(); resources.BaseDirectory = TempDirectory; resources.DynamicPrefix = true; PerformDependentResxTests(cscTask, resources); }
public void Test_ManifestResourceName_PrefixWithSpecialCharacters() { ResourceFileSet fileset = new ResourceFileSet(); fileset.BaseDirectory = TempDirectory; fileset.DynamicPrefix = true; string actualName; // if part of the prefix starts with a number, it should be // prefixed with an underscore fileset.Prefix = @"Root.1MyProj.Howdy"; actualName = fileset.GetManifestResourceName(Path.Combine( fileset.BaseDirectory.FullName, "mydir" + Path.DirectorySeparatorChar + "file.txt")); Assert.AreEqual("Root._1MyProj.Howdy" + ".mydir.file.txt", actualName, "Incorrect manifest resource name."); // any character in the prefix that is neither letter nor digit should // be replaced with an underscore fileset.Prefix = @"Root.-MyProj.H0w!dy"; actualName = fileset.GetManifestResourceName(Path.Combine( fileset.BaseDirectory.FullName, "mydir" + Path.DirectorySeparatorChar + "file.txt")); Assert.AreEqual("Root._MyProj.H0w_dy" + ".mydir.file.txt", actualName, "Incorrect manifest resource name."); // the file name part of a manifest resource name can start with a // digit fileset.Prefix = @"Root.MyProj.Howdy"; actualName = fileset.GetManifestResourceName(Path.Combine( fileset.BaseDirectory.FullName, "mydir" + Path.DirectorySeparatorChar + "1file.txt")); Assert.AreEqual("Root.MyProj.Howdy" + ".mydir.1file.txt", actualName, "Incorrect manifest resource name."); // the extension part of a manifest resource name can start with a // digit fileset.Prefix = @"Root.MyProj.Howdy"; actualName = fileset.GetManifestResourceName(Path.Combine( fileset.BaseDirectory.FullName, "mydir" + Path.DirectorySeparatorChar + "file.1txt")); Assert.AreEqual("Root.MyProj.Howdy" + ".mydir.file.1txt", actualName, "Incorrect manifest resource name."); // the file name part of a manifest resource name can contain // characters that are neither letter nor digit fileset.Prefix = @"Root.MyProj.Howdy"; actualName = fileset.GetManifestResourceName(Path.Combine( fileset.BaseDirectory.FullName, "mydir" + Path.DirectorySeparatorChar + "f-ile.txt")); Assert.AreEqual("Root.MyProj.Howdy" + ".mydir.f-ile.txt", actualName, "Incorrect manifest resource name."); // the extension part of a manifest resource name can contain // characters that are neither letter nor digit fileset.Prefix = @"Root.MyProj.Howdy"; actualName = fileset.GetManifestResourceName(Path.Combine( fileset.BaseDirectory.FullName, "mydir" + Path.DirectorySeparatorChar + "file.t!xt")); Assert.AreEqual("Root.MyProj.Howdy" + ".mydir.file.t!xt", actualName, "Incorrect manifest resource name."); }
/// <summary> /// Determines the manifest resource name of the given resource file. /// </summary> /// <param name="resources">The <see cref="ResourceFileSet" /> containing information that will used to assemble the manifest resource name.</param> /// <param name="resourcePhysicalFile">The resource file of which the manifest resource name should be determined.</param> /// <param name="resourceLogicalFile">The logical location of the resource file.</param> /// <param name="dependentFile">The source file on which the resource file depends.</param> /// <returns> /// The manifest resource name of the specified resource file. /// </returns> public string GetManifestResourceName(ResourceFileSet resources, string resourcePhysicalFile, string resourceLogicalFile, string dependentFile) { if (resources == null) { throw new ArgumentNullException("resources"); } if (resourcePhysicalFile == null) { throw new ArgumentNullException("resourcePhysicalFile"); } if (resourceLogicalFile == null) { throw new ArgumentNullException("resourceLogicalFile"); } // make sure the resource file exists if (!File.Exists(resourcePhysicalFile)) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA2009"), resourcePhysicalFile), Location); } // will hold the manifest resource name string manifestResourceName = null; // check if we're dealing with a localized resource CultureInfo resourceCulture = CompilerBase.GetResourceCulture( resourceLogicalFile, dependentFile); // determine the resource type switch (Path.GetExtension(resourcePhysicalFile).ToLower(CultureInfo.InvariantCulture)) { case ".resx": // try and get manifest resource name from dependent file ResourceLinkage resourceLinkage = GetResourceLinkage( dependentFile, resourceCulture); if (resourceLinkage == null || !resourceLinkage.IsValid) { // no resource linkage could be determined (no dependent // file or dependent file does not exist) or dependent // file is no (valid) source file manifestResourceName = Path.ChangeExtension( resources.GetManifestResourceName(resourcePhysicalFile, resourceLogicalFile), "resources"); } else { if (!resourceLinkage.HasClassName) { // use filename of resource file to determine class name string className = Path.GetFileNameWithoutExtension( resourcePhysicalFile); // cater for asax/aspx special cases. eg. a resource file // named "WebForm1.aspx(.resx)" will here be transformed to // "WebForm1" // we assume that the class name of a codebehind file // is equal to the file name of that codebehind file // (without extension) if (Path.GetExtension(className) != string.Empty) { string codebehindExtension = Path.GetExtension( className).ToLower(CultureInfo.InvariantCulture); foreach (string extension in CodebehindExtensions) { if (extension == codebehindExtension) { className = Path.GetFileNameWithoutExtension( className); break; } } } resourceLinkage.ClassName = className; } // ensure we have information necessary to determine the // manifest resource name if (resourceLinkage.IsValid) { manifestResourceName = resourceLinkage.ToString() + ".resources"; } else { // we should actually never get here, but just in case ... throw new BuildException(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA2010"), resourcePhysicalFile), Location); } } break; case ".resources": // determine resource name, and leave culture information // in manifest resource name manifestResourceName = resources.GetManifestResourceName( resourcePhysicalFile, resourceLogicalFile); break; default: // VS.NET handles an embedded resource file named licenses.licx // in the root of the project and without culture in a special // way if (Path.GetFileName(resourcePhysicalFile) == "licenses.licx") { // the manifest resource name will be <output file>.licenses // eg. TestAssembly.exe.licenses manifestResourceName = Path.GetFileName(OutputFile.FullName) + ".licenses"; } else { // check if resource is localized if (resourceCulture != null) { // determine resource name manifestResourceName = resources.GetManifestResourceName( resourcePhysicalFile, resourceLogicalFile); // remove culture name from name of resource int cultureIndex = manifestResourceName.LastIndexOf("." + resourceCulture.Name); manifestResourceName = manifestResourceName.Substring(0, cultureIndex) + manifestResourceName.Substring(cultureIndex).Replace("." + resourceCulture.Name, string.Empty); } else { manifestResourceName = resources.GetManifestResourceName( resourcePhysicalFile, resourceLogicalFile); } } break; } return manifestResourceName; }
private void PerformDependentResxTests(VbcTask vbcTask, ResourceFileSet resources) { // holds the path to the resource file string resourceFile = null; // initialize resource file resourceFile = Path.Combine(resources.BaseDirectory.FullName, "ResourceFile.resx"); // create resource file CreateTempFile(resourceFile); // create dependent file TempFile.CreateWithContents(_sourceCodeWithNamespace, Path.Combine( resources.BaseDirectory.FullName, "ResourceFile." + vbcTask.Extension)); // assert manifest resource name Assert.AreEqual(vbcTask.RootNamespace + ".ResourceTest.HelloWorld.resources", vbcTask.GetManifestResourceName(resources, resourceFile)); // initialize resource file resourceFile = Path.Combine(resources.BaseDirectory.FullName, "ResourceFile.resx"); // create resource file CreateTempFile(resourceFile); // create dependent file TempFile.CreateWithContents(_sourceCode, Path.Combine( resources.BaseDirectory.FullName, "ResourceFile." + vbcTask.Extension)); // assert manifest resource name Assert.AreEqual(vbcTask.RootNamespace + ".HelloWorld.resources", vbcTask.GetManifestResourceName(resources, resourceFile)); // initialize resource file resourceFile = Path.Combine(resources.BaseDirectory.FullName, "ResourceFile.en-US.resx"); // create resource file CreateTempFile(resourceFile); // create dependent file TempFile.CreateWithContents(_sourceCodeWithNamespace, Path.Combine( resources.BaseDirectory.FullName, "ResourceFile." + vbcTask.Extension)); // assert manifest resource name Assert.AreEqual(vbcTask.RootNamespace + ".ResourceTest.HelloWorld.en-US.resources", vbcTask.GetManifestResourceName(resources, resourceFile)); // initialize resource file resourceFile = Path.Combine(resources.BaseDirectory.FullName, "ResourceFile.en-US.resx"); // create resource file CreateTempFile(resourceFile); // create dependent file TempFile.CreateWithContents(_sourceCode, Path.Combine( resources.BaseDirectory.FullName, "ResourceFile." + vbcTask.Extension)); // assert manifest resource name Assert.AreEqual(vbcTask.RootNamespace + ".HelloWorld.en-US.resources", vbcTask.GetManifestResourceName(resources, resourceFile)); // initialize resource file resourceFile = Path.Combine(resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar + "ResourceFile.resx"); // create resource file CreateTempFile(resourceFile); // create dependent file TempFile.CreateWithContents(_sourceCodeWithNamespace, Path.Combine( resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar + "ResourceFile." + vbcTask.Extension)); // assert manifest resource name Assert.AreEqual(vbcTask.RootNamespace + ".ResourceTest.HelloWorld.resources", vbcTask.GetManifestResourceName(resources, resourceFile)); // initialize resource file resourceFile = Path.Combine(resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar + "ResourceFile.resx"); // create resource file CreateTempFile(resourceFile); // create dependent file TempFile.CreateWithContents(_sourceCode, Path.Combine( resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar + "ResourceFile." + vbcTask.Extension)); // assert manifest resource name Assert.AreEqual(vbcTask.RootNamespace + ".HelloWorld.resources", vbcTask.GetManifestResourceName(resources, resourceFile)); // initialize resource file resourceFile = Path.Combine(resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar + "ResourceFile.en-US.resx"); // create resource file CreateTempFile(resourceFile); // create dependent file TempFile.CreateWithContents(_sourceCodeWithNamespace, Path.Combine( resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar + "ResourceFile." + vbcTask.Extension)); // assert manifest resource name Assert.AreEqual(vbcTask.RootNamespace + ".ResourceTest.HelloWorld.en-US.resources", vbcTask.GetManifestResourceName(resources, resourceFile)); // initialize resource file resourceFile = Path.Combine(resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar + "ResourceFile.en-US.resx"); // create resource file CreateTempFile(resourceFile); // create dependent file TempFile.CreateWithContents(_sourceCode, Path.Combine( resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar + "ResourceFile." + vbcTask.Extension)); // assert manifest resource name Assert.AreEqual(vbcTask.RootNamespace + ".HelloWorld.en-US.resources", vbcTask.GetManifestResourceName(resources, resourceFile)); // initialize resource file resourceFile = Path.Combine(resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar + "ResourceFile.en-US.dunno.en-US.resx"); // create resource file CreateTempFile(resourceFile); // create dependent file TempFile.CreateWithContents(_sourceCodeWithNamespace, Path.Combine( resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar + "ResourceFile.en-US.dunno." + vbcTask.Extension)); // assert manifest resource name Assert.AreEqual(vbcTask.RootNamespace + ".ResourceTest.HelloWorld.en-US.resources", vbcTask.GetManifestResourceName(resources, resourceFile)); // initialize resource file resourceFile = Path.Combine(resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar + "ResourceFile.en-US.dunno.en-US.resx"); // create resource file CreateTempFile(resourceFile); // create dependent file TempFile.CreateWithContents(_sourceCode, Path.Combine( resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar + "ResourceFile.en-US.dunno." + vbcTask.Extension)); // assert manifest resource name Assert.AreEqual(vbcTask.RootNamespace + ".HelloWorld.en-US.resources", vbcTask.GetManifestResourceName(resources, resourceFile)); }
public void Test_ManifestResourceName_CompiledResource_Prefix() { VbcTask vbcTask = new VbcTask(); vbcTask.Project = CreateEmptyProject(); vbcTask.RootNamespace = "TestRootNamespace"; ResourceFileSet resources = new ResourceFileSet(); resources.BaseDirectory = TempDirectory; resources.Prefix = "TestNamespace"; resources.DynamicPrefix = false; // holds the path to the resource file string resourceFile = null; // initialize resource file resourceFile = Path.Combine(resources.BaseDirectory.FullName, "ResourceFile.resources"); // create resource file CreateTempFile(resourceFile); // assert manifest resource name Assert.AreEqual(resources.Prefix + "." + "ResourceFile.resources", vbcTask.GetManifestResourceName(resources, resourceFile)); // initialize resource file resourceFile = Path.Combine(resources.BaseDirectory.FullName, "ResourceFile.en-US.resources"); // create resource file CreateTempFile(resourceFile); // assert manifest resource name Assert.AreEqual(resources.Prefix + "." + "ResourceFile.en-US.resources", vbcTask.GetManifestResourceName(resources, resourceFile)); // initialize resource file resourceFile = Path.Combine(resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar + "ResourceFile.resources"); // create resource file CreateTempFile(resourceFile); // assert manifest resource name Assert.AreEqual(resources.Prefix + "." + "ResourceFile.resources", vbcTask.GetManifestResourceName(resources, resourceFile)); // initialize resource file resourceFile = Path.Combine(resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar + "ResourceFile.en-US.resources"); // create resource file CreateTempFile(resourceFile); // assert manifest resource name Assert.AreEqual(resources.Prefix + "." + "ResourceFile.en-US.resources", vbcTask.GetManifestResourceName(resources, resourceFile)); }
public void Test_ManifestResourceName_Resx_Prefix() { VbcTask vbcTask = new VbcTask(); vbcTask.Project = CreateEmptyProject(); vbcTask.RootNamespace = "TestRootNamespace"; ResourceFileSet resources = new ResourceFileSet(); resources.BaseDirectory = TempDirectory; resources.Prefix = "TestNamespace"; resources.DynamicPrefix = false; // prefix should be ignored for resx files PerformDependentResxTests(vbcTask, resources); }
public void Test_ManifestResourceName_Resx_DynamicPrefix() { VbcTask vbcTask = new VbcTask(); vbcTask.Project = CreateEmptyProject(); vbcTask.RootNamespace = "TestRootNamespace"; ResourceFileSet resources = new ResourceFileSet(); resources.BaseDirectory = TempDirectory; resources.DynamicPrefix = true; PerformDependentResxTests(vbcTask, resources); }
public void Test_ManifestResourceName_NonExistingResource() { VbcTask vbcTask = new VbcTask(); vbcTask.Project = CreateEmptyProject(); ResourceFileSet resources = new ResourceFileSet(); resources.BaseDirectory = TempDirectory; resources.DynamicPrefix = true; vbcTask.GetManifestResourceName(resources, "I_dont_exist.txt"); }
/// <summary> /// Creates a shallow copy of the <see cref="ResourceFileSet" />. /// </summary> /// <returns> /// A shallow copy of the <see cref="ResourceFileSet" />. /// </returns> public override object Clone() { ResourceFileSet clone = new ResourceFileSet(); base.CopyTo(clone); clone._dynamicprefix = _dynamicprefix; clone._prefix = _prefix; return clone; }
public void Test_ManifestResourceName_Resx_StandAlone_DynamicPrefix_With_Prefix() { CscTask cscTask = new CscTask(); cscTask.Project = CreateEmptyProject(); ResourceFileSet resources = new ResourceFileSet(); resources.BaseDirectory = TempDirectory; resources.Prefix = "TestNamespace"; resources.DynamicPrefix = true; // holds the path to the resource file string resourceFile = null; // initialize resource file resourceFile = Path.Combine(resources.BaseDirectory.FullName, "ResourceFile.resx"); // create resource file CreateTempFile(resourceFile); // assert manifest resource name Assert.AreEqual(resources.Prefix + "." + "ResourceFile.resources", cscTask.GetManifestResourceName(resources, resourceFile)); // initialize resource file resourceFile = Path.Combine(resources.BaseDirectory.FullName, "ResourceFile.en-US.resx"); // create resource file CreateTempFile(resourceFile); // assert manifest resource name Assert.AreEqual(resources.Prefix + "." + "ResourceFile.en-US.resources", cscTask.GetManifestResourceName(resources, resourceFile)); // initialize resource file resourceFile = Path.Combine(resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar + "ResourceFile.resx"); // create resource file CreateTempFile(resourceFile); // assert manifest resource name Assert.AreEqual(resources.Prefix + "." + "SubDir" + "." + "ResourceFile.resources", cscTask.GetManifestResourceName( resources, resourceFile)); // initialize resource file resourceFile = Path.Combine(resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar + "ResourceFile.en-US.resx"); // create resource file CreateTempFile(resourceFile); // assert manifest resource name Assert.AreEqual(resources.Prefix + "." + "SubDir" + "." + "ResourceFile.en-US.resources", cscTask.GetManifestResourceName( resources, resourceFile)); // initialize resource file resourceFile = Path.Combine(resources.BaseDirectory.FullName, "SubDir" + Path.DirectorySeparatorChar + "ResourceFile.en-US.dunno.en-US.resx"); // create resource file CreateTempFile(resourceFile); // assert manifest resource name Assert.AreEqual(resources.Prefix + "." + "SubDir" + "." + "ResourceFile.en-US.dunno.en-US.resources", cscTask.GetManifestResourceName( resources, resourceFile)); }
/// <summary> /// Adds the elements of a <see cref="ResourceFileSet"/> array to the end of the collection. /// </summary> /// <param name="items">The array of <see cref="ResourceFileSet"/> elements to be added to the end of the collection.</param> public void AddRange(ResourceFileSet[] items) { for (int i = 0; (i < items.Length); i = (i + 1)) { Add(items[i]); } }
protected void RunCscTask() { CscTask csc = new CscTask(); this.CopyTo(csc); if (this.Project.PlatformName == "unix") { // on Windows this is csc, but on Mono on Linux or Mac we need mcs csc.ExeName = "mcs"; } XmlDocument doc = new XmlDocument(); doc.Load(FCSProjFile); XmlNode propertyGroup = doc.DocumentElement.FirstChild; Dictionary <string, string>mainProperties = new Dictionary <string, string>(); foreach (XmlNode propNode in propertyGroup.ChildNodes) { mainProperties.Add(propNode.Name, propNode.InnerText); } string OutputFile = Path.GetFullPath(Path.GetDirectoryName(FCSProjFile) + "/" + mainProperties["OutputPath"].Replace("\\", "/")); OutputFile += "/" + mainProperties["AssemblyName"]; if (mainProperties["OutputType"].ToLower() == "library") { OutputFile += ".dll"; } else { OutputFile += ".exe"; } csc.OutputFile = new FileInfo(OutputFile); csc.DocFile = new FileInfo(mainProperties["DocumentationFile"]); csc.OutputTarget = mainProperties["OutputType"]; // needed because of sqlite3.dll, when compiling on Linux for Windows if (this.Project.PlatformName == "unix") { csc.Platform = "x86"; } csc.Define = "DEBUGMODE"; String FrameworkDLLPath = Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(System.Type)).Location); foreach (XmlNode ProjectNodeChild in doc.DocumentElement) { if (ProjectNodeChild.Name == "ItemGroup") { foreach (XmlNode ItemNode in ProjectNodeChild) { if (ItemNode.Name == "Reference") { if (ItemNode.HasChildNodes && (ItemNode.ChildNodes[0].Name == "HintPath")) { csc.References.AsIs.Add(ItemNode.ChildNodes[0].InnerText); } else { // .net dlls csc.References.AsIs.Add( FrameworkDLLPath + Path.DirectorySeparatorChar + ItemNode.Attributes["Include"].Value + ".dll"); } } else if (ItemNode.Name == "ProjectReference") { string ReferencedProjectName = ItemNode.ChildNodes[1].InnerText; csc.References.AsIs.Add( Path.GetDirectoryName(OutputFile) + Path.DirectorySeparatorChar + ReferencedProjectName + ".dll"); } else if (ItemNode.Name == "Compile") { csc.Sources.AsIs.Add(ItemNode.Attributes["Include"].Value); } else if (ItemNode.Name == "EmbeddedResource") { ResourceFileSet fs = new ResourceFileSet(); fs.AsIs.Add(ItemNode.Attributes["Include"].Value); csc.ResourcesList.Add(fs); } } } } csc.Execute(); }
/// <summary> /// Determines whether a <see cref="ResourceFileSet"/> is in the collection. /// </summary> /// <param name="item">The <see cref="ResourceFileSet"/> to locate in the collection.</param> /// <returns> /// <see langword="true" /> if <paramref name="item"/> is found in the /// collection; otherwise, <see langword="false" />. /// </returns> public bool Contains(ResourceFileSet item) { return base.List.Contains(item); }
/// <summary> /// Determines the manifest resource name of the given resource file. /// </summary> /// <param name="resources">The <see cref="ResourceFileSet" /> containing information that will used to assemble the manifest resource name.</param> /// <param name="resourceFile">The resource file of which the manifest resource name should be determined.</param> /// <returns> /// The manifest resource name of the specified resource file. /// </returns> /// <remarks> /// For .resx resources, the name of the dependent is determined by /// replacing the extension of the file with the extension of the /// source files for the compiler, and removing the culture name from /// the file name for localized resources. /// </remarks> public string GetManifestResourceName(ResourceFileSet resources, string resourceFile) { if (resources == null) { throw new ArgumentNullException("resources"); } if (resourceFile == null) { throw new ArgumentNullException("resourceFile"); } // make sure the resource file exists if (!File.Exists(resourceFile)) { throw new BuildException(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("NA2009"), resourceFile), Location); } // determine the resource type switch (Path.GetExtension(resourceFile).ToLower(CultureInfo.InvariantCulture)) { case ".resx": // open matching source file if it exists string dependentFile = Path.ChangeExtension(resourceFile, Extension); // check if we're dealing with a localized resource CultureInfo resourceCulture = CompilerBase.GetResourceCulture(resourceFile, dependentFile); // remove last occurrence of culture name from dependent file // for localized resources if (resourceCulture != null) { int index = dependentFile.LastIndexOf("." + resourceCulture.Name); if (index >= 0) { if ((index + resourceCulture.Name.Length + 1) < dependentFile.Length) { dependentFile = dependentFile.Substring(0, index) + dependentFile.Substring(index + resourceCulture.Name.Length + 1); } else { dependentFile = dependentFile.Substring(0, index); } } } // determine the manifest resource name using the given // dependent file return GetManifestResourceName(resources, resourceFile, resourceFile, dependentFile); default: // for non-resx resources, a dependent file has no influence // on the manifest resource name return GetManifestResourceName(resources, resourceFile, resourceFile, null); } }
/// <summary> /// Copies the entire collection to a compatible one-dimensional array, starting at the specified index of the target array. /// </summary> /// <param name="array">The one-dimensional array that is the destination of the elements copied from the collection. The array must have zero-based indexing.</param> /// <param name="index">The zero-based index in <paramref name="array"/> at which copying begins.</param> public void CopyTo(ResourceFileSet[] array, int index) { base.List.CopyTo(array, index); }
/// <summary> /// Retrieves the index of a specified <see cref="ResourceFileSet"/> object in the collection. /// </summary> /// <param name="item">The <see cref="ResourceFileSet"/> object for which the index is returned.</param> /// <returns> /// The index of the specified <see cref="ResourceFileSet"/>. If the <see cref="ResourceFileSet"/> is not currently a member of the collection, it returns -1. /// </returns> public int IndexOf(ResourceFileSet item) { return base.List.IndexOf(item); }
private string GetManifestResourceNameJSharp(ConfigurationSettings configSetting, string dependentFile) { // defer to the resource management code in VjcTask VjcTask vjc = new VjcTask(); vjc.Project = _solutionTask.Project; vjc.NamespaceManager = _solutionTask.NamespaceManager; vjc.OutputFile = new FileInfo(FileUtils.CombinePaths(configSetting.OutputDir.FullName, Project.ProjectSettings.OutputFileName)); // set-up resource fileset ResourceFileSet resources = new ResourceFileSet(); resources.Project = _solutionTask.Project; resources.NamespaceManager = _solutionTask.NamespaceManager; resources.Parent = vjc; resources.BaseDirectory = new DirectoryInfo(Path.GetDirectoryName( Project.ProjectPath)); resources.Prefix = Project.ProjectSettings.RootNamespace; resources.DynamicPrefix = true; // bug #1042917: use logical location of resource file to determine // manifest resource name return vjc.GetManifestResourceName(resources, InputFile.FullName, LogicalFile.FullName, dependentFile); }