194
196
set { _supportsExternalFileReferences = value; }
200
/// For internal use only !
202
public ArrayList QualifiedResources {
203
get { return _qualifiedResources; }
197
206
#endregion Public Instance Properties
199
208
#region Private Instance Properties
201
210
private bool RequiresAssemblyReferences {
203
if (Resources.FileNames.Count > 0) {
212
if (Resources.FileNames.Count > 0 || QualifiedResources.Count > 0) {
204
213
foreach (string resourceFile in Resources.FileNames) {
205
214
if (ReferencesThirdPartyAssemblies(resourceFile)) {
219
foreach (QualifiedResource resource in QualifiedResources) {
220
if (ReferencesThirdPartyAssemblies(resource.Input.FullName)) {
209
224
} else if (InputFile != null) {
210
225
return ReferencesThirdPartyAssemblies(InputFile.FullName);
373
388
Resources.BaseDirectory = new DirectoryInfo(Project.BaseDirectory);
377
if (Resources.FileNames.Count > 0) {
392
_arguments.Length = 0;
394
if (Resources.FileNames.Count > 0 || QualifiedResources.Count > 0) {
378
395
if (OutputFile != null) {
379
396
throw new BuildException(ResourceUtils.GetString("NA2026"), Location);
381
foreach (string filename in Resources.FileNames) {
399
foreach (string fileName in Resources.FileNames) {
400
FileInfo inputFile = new FileInfo(fileName);
382
401
FileInfo outputFile = GetOutputFile(new FileInfo(Path.Combine(
383
Path.GetDirectoryName(filename), Resources.GetManifestResourceName(filename))));
385
if (NeedsCompiling(new FileInfo(filename), outputFile)) {
386
// ensure output directory exists
387
if (!outputFile.Directory.Exists) {
388
outputFile.Directory.Create();
391
string cmdLineArg = string.Format(CultureInfo.InvariantCulture,
392
" \"{0},{1}\"", filename, outputFile.FullName);
394
// check if adding arguments to compile current resx to
395
// total command line would cause it to exceed maximum
397
bool maxCmdLineExceeded = (_arguments.Length + cmdLineArg.Length > _maxCmdLineLength);
399
// if this is the first resx that we're compiling, or the
400
// first one of the next execution of the resgen tool, then
401
// add options to command line
402
if (StringUtils.IsNullOrEmpty(_arguments) || maxCmdLineExceeded) {
404
if (SupportsExternalFileReferences) {
405
cmdLineArg = " /usesourcepath";
407
Log(Level.Warning, ResourceUtils.GetString(
408
"String_ResourceCompilerDoesNotSupportExternalReferences"),
409
Project.TargetFramework.Description);
413
cmdLineArg = "/compile" + cmdLineArg;
416
// if maximum length would have been exceeded by compiling
417
// the current resx file, then first execute the resgen
419
if (maxCmdLineExceeded) {
421
// call base class to do the work
424
// we only need to remove temporary directory when
425
// an error occurred and if it was actually created
426
if (_workingDirectory != null) {
427
// delete temporary directory and all files in it
428
DeleteTask deleteTask = new DeleteTask();
429
deleteTask.Project = Project;
430
deleteTask.Parent = this;
431
deleteTask.InitializeTaskConfiguration();
432
deleteTask.Directory = _workingDirectory;
433
deleteTask.Threshold = Level.None; // no output in build log
434
deleteTask.Execute();
441
// reset command line arguments as we've processed them
442
_arguments = string.Empty;
445
// append command line arguments to compile current resx
446
// file to the total command line
447
AppendArgument(cmdLineArg);
402
inputFile.DirectoryName, Resources.GetManifestResourceName(fileName))));
403
WriteCommandLineOptions(inputFile, outputFile);
406
// used by <solution> task
407
foreach (QualifiedResource resource in QualifiedResources) {
408
WriteCommandLineOptions(resource.Input, resource.Output);
451
411
// Single file situation
641
596
using (StreamReader sr = new StreamReader(resourceFile, true)) {
642
597
XPathDocument xpathDoc = new XPathDocument(new XmlTextReader(sr));
644
// determine the number of <data> elements that have a "type"
645
// attribute with a value that does not start with "System."
646
// and is not fully qualified
647
int count = xpathDoc.CreateNavigator().Select("/root/data[@type and not(starts-with(@type, 'System.') and contains(@type,'PublicKeyToken='))]").Count;
599
// determine the number of <data> elements that either have
600
// a "mimetype" attribute (meaning it contains a serialized
601
// instance that might be of a referenced assembly) or a
602
// "type" attribute with a value that does not start with
603
// "System." and is not fully qualified
604
int count = xpathDoc.CreateNavigator().Select("/root/data[@mimetype or (@type and not(starts-with(@type, 'System.') and contains(@type,'PublicKeyToken=')))]").Count;
649
606
// if there are no <data> elements of a third party type, we
650
607
// assume that the resource file does not reference types from
666
private void WriteCommandLineOptions(FileInfo inputFile, FileInfo outputFile) {
667
if (NeedsCompiling(inputFile, outputFile)) {
668
// ensure output directory exists
669
if (!outputFile.Directory.Exists) {
670
outputFile.Directory.Create();
673
string cmdLineArg = string.Format(CultureInfo.InvariantCulture,
674
" \"{0},{1}\"", inputFile, outputFile.FullName);
676
// check if adding arguments to compile current resx to
677
// total command line would cause it to exceed maximum
679
bool maxCmdLineExceeded = (_arguments.Length + cmdLineArg.Length > _maxCmdLineLength);
681
// if this is the first resx that we're compiling, or the
682
// first one of the next execution of the resgen tool, then
683
// add options to command line
684
if (_arguments.Length == 0 || maxCmdLineExceeded) {
686
if (SupportsExternalFileReferences) {
687
cmdLineArg = " /useSourcePath /compile" + cmdLineArg;
689
cmdLineArg = " /compile" + cmdLineArg;
691
Log(Level.Warning, ResourceUtils.GetString(
692
"String_ResourceCompilerDoesNotSupportExternalReferences"),
693
Project.TargetFramework.Description);
696
cmdLineArg = "/compile" + cmdLineArg;
700
// if maximum length would have been exceeded by compiling
701
// the current resx file, then first execute the resgen
703
if (maxCmdLineExceeded) {
705
// call base class to do the work
708
// we only need to remove temporary directory when
709
// an error occurred and if it was actually created
710
if (_workingDirectory != null) {
711
// delete temporary directory and all files in it
712
DeleteTask deleteTask = new DeleteTask();
713
deleteTask.Project = Project;
714
deleteTask.Parent = this;
715
deleteTask.InitializeTaskConfiguration();
716
deleteTask.Directory = _workingDirectory;
717
deleteTask.Threshold = Level.None; // no output in build log
718
deleteTask.Execute();
725
// reset command line arguments as we've processed them
726
_arguments.Length = 0;
729
// append command line arguments to compile current resx
730
// file to the total command line
731
_arguments.Append(cmdLineArg);
709
735
#endregion Private Instance Methods
739
/// For internal use only !
741
public class QualifiedResource {
742
#region Private Instance Fields
744
private FileInfo _inputFile;
745
private FileInfo _outputFile;
747
#endregion Private Instance Fields
749
#region Public Instance Constructors
752
/// Initializes a new instance of the <see cref="QualifiedResource" />
753
/// class for a given input and output file.
755
/// <param name="input">The resource to compile.</param>
756
/// <param name="output">The compiled resource.</param>
757
public QualifiedResource(FileInfo input, FileInfo output) {
759
_outputFile = output;
762
#endregion Public Instance Constructors
764
#region Public Instance Properties
767
/// Gets the resource file to compile.
770
/// The resource file to compile.
772
public FileInfo Input {
773
get { return _inputFile; }
777
/// Gets the compiled resource file.
780
/// The compiled resource file.
782
public FileInfo Output {
783
get { return _outputFile; }
786
#endregion Public Instance Properties