Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

Change the generated names for resources #1486

Merged
merged 1 commit into from
Mar 26, 2015
Merged

Conversation

victorhurdugaci
Copy link
Contributor

Fixes #502 and #898

Please review @davidfowl @lodejard

Notice there is some code that I copied from MsBuild.

cc @anure you will have to rebase on top of this

@ghost ghost added the cla-not-required label Mar 24, 2015
@victorhurdugaci
Copy link
Contributor Author

PS: tested on mono and it works

/// </summary>
/// <param name="name"></param>
/// <returns></returns>
private static string MakeValidEverettIdentifier(string name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know what "Everett" means here, but it might be good to either: a) put a comment above explaining what "Everett" means here or b) rename the methods to the actual VS version name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's code copied from MsBuild, even the comments (I put a reference above)

@analogrelay
Copy link
Contributor

Looks pretty good so far. A few comments. I'll rebase my PR on it, it shouldn't be too bad. I expect that ResourceDescriptor will move to Runtime.Interfaces in my PR so that Roslyn can use it, or I may introduce an interface. Either way, it shouldn't be a major impact and I'll handle it in my PR.

@@ -121,7 +121,24 @@ public class RoslynCompiler

compilation = ApplyVersionInfo(compilation, project, parseOptions);

var compilationContext = new CompilationContext(compilation, project, target.TargetFramework, target.Configuration);
CompositeResourceProvider resourceProvider = new CompositeResourceProvider(new IResourceProvider[]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of the code shouldn't know anything about resource providers.

@victorhurdugaci
Copy link
Contributor Author

Updated to address the comments from @anurse and @davidfowl

@@ -13,7 +13,7 @@ public class ProjectFilesCollection
public static readonly string[] DefaultBundleExcludePatterns = new[] { @"obj/**/*.*", @"bin/**/*.*", @"**/.*/**" };
public static readonly string[] DefaultPreprocessPatterns = new[] { @"compiler/preprocess/**/*.cs" };
public static readonly string[] DefaultSharedPatterns = new[] { @"compiler/shared/**/*.cs" };
public static readonly string[] DefaultResourcesPatterns = new[] { @"compiler/resources/**/*" };
public static readonly string[] DefaultResourcesPatterns = new[] { @"compiler/resources/**/*.resx" };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't right. There should be 2 default resource patterns. This array should have:

public static readonly string[] DefaultResourcesPatterns = new[] { @"compiler/resources/**/*", "**/*.resx" };

@victorhurdugaci
Copy link
Contributor Author

@davidfowl updated

@davidfowl
Copy link
Member

Very nice. Now I'm going to pull it down and try it.

@victorhurdugaci
Copy link
Contributor Author

Let me rebase it first

@victorhurdugaci
Copy link
Contributor Author

@davidfowl you can try now

@analogrelay
Copy link
Contributor

Can we get this in soon? @davidfowl are you good with it now?

@davidfowl
Copy link
Member

This will break all of the other e repertories. Do you have a change ready for them?

@davidfowl
Copy link
Member

Wow, repositories

@victorhurdugaci
Copy link
Contributor Author

Actually, I don't think it will break in too many places. All I have to do is change the resource generator in Universe.

But hold on because I found a bug.

@victorhurdugaci
Copy link
Contributor Author

It works with the existing code because we generate the same names. In the second iteration I changed the name of the resx files to always have the .resources extension. Otherwise, the resource manager cannot read them.

@davidfowl
Copy link
Member

If this doesn't break then we did something wrong.

@davidfowl
Copy link
Member

Tried out the resource sharing scenario and that's still busted. It's a tricky one too. If you share resources with another project from a project.json based project, the resource names will be for the project.json based project instead of the project we're using. This makes the logical names wrong and it makes using those resources at runtime fail:

ClassLibrary58

using System;

namespace ClassLibrary58
{
    public class Program
    {
        public void Main()
        {
            Console.WriteLine(ClassLibrary1.Resource1.Another);
        }
    }
}
{
    "version": "1.0.0-*",
    "commands": {
        "ClassLibrary58": "ClassLibrary58"
    },
    "compile": [ "**/*.cs", "../../ClassLibrary1/**/*.cs" ],
    "resource": [ "../../ClassLibrary1/**/*.resx" ],
    "frameworks": {
        "dnx451": {
            "dependencies": {
            }
        }
    }
}

The generated code from Resource1:

[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Resources.ResourceManager ResourceManager {
            get {
                if (object.ReferenceEquals(resourceMan, null)) {
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ClassLibrary1.Resource1", typeof(Resource1).GetTypeInfo().Assembly);
                    resourceMan = temp;
                }
                return resourceMan;
            }
        }

This breaks because:

image

This is the case where we need to be able to specify the project root for a resource name.

{
  "resource": [
        {
            "pattern": "../../ClassLibrary1/**/*.resx",
            "logicalName": "ClassLibrary1"

        }
    ],
}

What do you think?

/cc @troydai @lodejard @anurse

@analogrelay
Copy link
Contributor

It does look like we need to adjust that. Can I ask that we try to get this PR in ASAP and maybe file a bug for immediate follow-up for that issue? Is the base functionality broken or are we just talking about fixing a specific scenario?

The compilation refactor is really itching to be pushed (so I can get new runtime compilation going and all that fun stuff) and it's a non-trivial rebase.

I don't want to do that rebasing if this PR is going to be rebased (making me rerebase and thus reresad).

@victorhurdugaci
Copy link
Contributor Author

Yes, I will get this PR merged soon and then start another one for the project.json changes.

@analogrelay
Copy link
Contributor

👍 Thanks much!

@victorhurdugaci
Copy link
Contributor Author

Because of bootstrapping issues, I hacked the code to generate both old and new resource names. Therefore, this change should not break anything.

I am going to merge it

@victorhurdugaci victorhurdugaci merged commit 6890623 into dev Mar 26, 2015
@victorhurdugaci victorhurdugaci deleted the victorhu/resxrename branch March 26, 2015 21:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clean up paths for relative embedded resources
3 participants