markpflug / sylvan.buildtools.resources Goto Github PK
View Code? Open in Web Editor NEWBuild-time resource file support in C# projects.
License: MIT License
Build-time resource file support in C# projects.
License: MIT License
I want to use the JsonResource to implement language text in my views. It work in all cs files I have but if I want to use it in any view I got the problem that the Localizer class is inaccessible. How can I fix this?
Error:
error CS0122: 'Localizer' is inaccessible due to its protection level [/home/workbranch/mvc/mvc.csproj]
View file example:
<div class="row mb-4">
<div class="col-12">
<div class="card">
<div class="card-header">
<div class="card-header-title">
@JsonLocalizer.Localizer.Farewell
</div>
<div class="card-small-headline">
Abwasser-, Wasser-, Gasanlagen
</div>
</div>
csproj file:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>1.0.3</Version>
</PropertyGroup>
<ItemGroup>
<JsonResource Update="Resources\Localizer.resj">
<Namespace>JsonLocalizer</Namespace>
</JsonResource>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Elemental.JsonResource" Version="0.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.0" />
<PackageReference Include="Microsoft.Build" Version="16.4.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.jQuery.Unobtrusive.Ajax" Version="3.2.6" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.0" />
<PackageReference Include="NetEscapades.AspNetCore.Identity.Validators" Version="1.3.1" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.0.1" />
</ItemGroup>
</Project>
I need to change the Accessmodifer to Public. Any Ideas?
Link: https://stackoverflow.com/questions/24833875/inaccessible-internal-resource-files/24833974
Figure out if it is possible to add a resj item template via nuget package. Currently, when adding a new resj via new text file, the project system will Remove
the JsonResource item, because the text file template isn't of that type. Requiring that people install a vsix or such would not really be acceptable.
Stack includes:
.nuget\packages\elemental.jsonresource\0.1.0-b005\build\Elemental.JsonResource.targets(45,3): error MSB4018: System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. Could not find or load a specific file.
Builds fine from VS and msbuild.
I'm using vscode and I wish the tooling would run whenever the resj file is edited, instead of having to save the csproj file over and over?
Hi Mark, this is a really valuable package !
I added a Resources.resj and a Resources.de.resj and a Resources.fr.resj file in a folder named Resources and the compilation works fine - the following dlls are generated:
But I can not find the generated classes. There is no namespaces MyProject.Resources. Could you precise how the generated classes are named and the namespace where they are placed?
Perhaps (probably) I am not knowledgeable enough. I would like to inject IStringLocalizer with the resource class generated by you.
Thanks a lot for any feedback !
Builds work in VS, but not from command line.
Currently, a key with a space (ie "Greeting Message") will break due to generating invalid code because the key is expected to be a valid C# identifier.
This can be fixed in (at least) one of two ways:
Modify the key to be valid be replacing any invalid characters with underscore.
Don't generate code for invalid key, and report that the identifier is invalid.
I'm leaning toward the second option, as the first has the potential to cause key conflicts after the replacements occur.
Hello,
First of all, thanks for the plugin (the generator part) that I just discovered today.
I use Dapper a lot so I write (big) sql queries.
When I test them, I use:
DECLARE @MyParameter INT = MyValue;
-- my big query
SELECT Id FROM MyTable WHERE Column = @MyParameter;
And then, before committing the code, I remove (or comment out) the DECLARE
part, because the parameter will be injected by Dapper (or any SqlParam). Since we use the same database in development, my co worker can easily debug my bad query by uncommenting the DECLARE
and then, fix the code :)
This is not perfect and error prone.
I thought about solution to simplify the workflow.
--MAGIC-COMMENT-START
DECLARE @Take INT = 10;
DECLARE @Skip INT = 0;
--MAGIC-COMMENT-END
The benefice using this would be something like:
--MAGIC-COMMENT-START
BEGIN TRANSACTION Tr;
--MAGIC-COMMENT-END
INSERT INTO Users (Name, Email) VALUES ('Foo', '[email protected]');
--MAGIC-COMMENT-START
ROLLBACK TRANSACTION Tr; -- don't really add to the database but useful to test syntax error
--MAGIC-COMMENT-END
I would also prevent vscode to hightlight my file in red becase some identifier are not declared.
I could also write a script that run all my sql file in the pipeline and see if they all work (that is a first step to tests) (since I have no tests for now)
What do you thing of this idea ? If you like it, would you be open to include this in the project ? (I can write the PR)
Best regards
Thanks for the great job creating this useful nugget package! Today when I tried to build my project from VS Code instead of VS, I wan't able to. I get build time errors as if your code-get did not work and get errors like the following.
The name 'Resources' does not exist in the current contextCS0103
Have you ever tested in VS Code?
I have this in my csproj file:
<ItemGroup>
<JsonResource Update="Resources.resj">
<AccessModifier>Public</AccessModifier>
<Namespace>PSDataverse</Namespace>
<ResourceName>Resources</ResourceName>
</JsonResource>
</ItemGroup>
also the following:
<ItemGroup>
<JsonResource Remove="Resources.resj" />
</ItemGroup>
<ItemGroup>
<None Remove="Resources.resj" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources.resj" />
</ItemGroup>
Not sure what's happening there.
Intellisense work bad with this error. Open this project in Visual Studio Code. You will get message: "There are unresolved dependencies. Please execute the restore command to continue. Source: C# (Extension)", press Restore. Press Ctrl+`, open OmniSharp Log. You will see in log this text:
[warn]: OmniSharp.MSBuild.ProjectManager
Failed to load project file '~/Documents/git/System-software-6-semester/UnitTest/UnitTest.csproj'.
~/Documents/git/System-software-6-semester/UnitTest/UnitTest.csproj(1,1)
Microsoft.Build.Exceptions.InvalidProjectFileException: The result "" of evaluating the value "$(JsonResourceTaskAssembly)" of the "AssemblyFile" attribute in element <UsingTask> is not valid. ~/.nuget/packages/elemental.jsonresource/0.2.0/build/Elemental.JsonResource.targets
at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject (System.String errorSubCategoryResourceName, Microsoft.Build.Shared.IElementLocation elementLocation, System.String resourceName, System.Object[] args) [0x00040] in <b695b16788dd418cbe8b4d98f7a92ff3>:0
at Microsoft.Build.Shared.ProjectErrorUtilities.VerifyThrowInvalidProject[T1,T2,T3,T4] (System.Boolean condition, System.String errorSubCategoryResourceName, Microsoft.Build.Shared.IElementLocation elementLocation, System.String resourceName, T1 arg0, T2 arg1, T3 arg2, T4 arg3) [0x00003] in <b695b16788dd418cbe8b4d98f7a92ff3>:0
at Microsoft.Build.Shared.ProjectErrorUtilities.VerifyThrowInvalidProject[T1,T2,T3,T4] (System.Boolean condition, Microsoft.Build.Shared.IElementLocation elementLocation, System.String resourceName, T1 arg0, T2 arg1, T3 arg2, T4 arg3) [0x00000] in <b695b16788dd418cbe8b4d98f7a92ff3>:0
at Microsoft.Build.Execution.TaskRegistry.RegisterTasksFromUsingTaskElement[P,I] (Microsoft.Build.BackEnd.Logging.ILoggingService loggingService, Microsoft.Build.Framework.BuildEventContext buildEventContext, System.String directoryOfImportingFile, Microsoft.Build.Construction.ProjectUsingTaskElement projectUsingTaskXml, Microsoft.Build.Execution.TaskRegistry taskRegistry, Microsoft.Build.Evaluation.Expander`2[P,I] expander, Microsoft.Build.Evaluation.ExpanderOptions expanderOptions, Microsoft.Build.Shared.FileSystem.IFileSystem fileSystem) [0x0011a] in <b695b16788dd418cbe8b4d98f7a92ff3>:0
at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].EvaluateUsingTaskElement (System.String directoryOfImportingFile, Microsoft.Build.Construction.ProjectUsingTaskElement projectUsingTaskElement) [0x00036] in <b695b16788dd418cbe8b4d98f7a92ff3>:0
at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].Evaluate (Microsoft.Build.BackEnd.Logging.ILoggingService loggingService, Microsoft.Build.Framework.BuildEventContext buildEventContext) [0x00391] in <b695b16788dd418cbe8b4d98f7a92ff3>:0
at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].Evaluate (Microsoft.Build.Evaluation.IEvaluatorData`4[P,I,M,D] data, Microsoft.Build.Construction.ProjectRootElement root, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, System.Int32 maxNodeCount, Microsoft.Build.Collections.PropertyDictionary`1[T] environmentProperties, Microsoft.Build.BackEnd.Logging.ILoggingService loggingService, Microsoft.Build.Evaluation.IItemFactory`2[S,T] itemFactory, Microsoft.Build.Evaluation.IToolsetProvider toolsetProvider, Microsoft.Build.Evaluation.ProjectRootElementCache projectRootElementCache, Microsoft.Build.Framework.BuildEventContext buildEventContext, Microsoft.Build.BackEnd.SdkResolution.ISdkResolverService sdkResolverService, System.Int32 submissionId, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext, System.Boolean interactive) [0x0002f] in <b695b16788dd418cbe8b4d98f7a92ff3>:0
at Microsoft.Build.Evaluation.Project.Reevaluate (Microsoft.Build.BackEnd.Logging.ILoggingService loggingServiceForEvaluation, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x0005e] in <b695b16788dd418cbe8b4d98f7a92ff3>:0
at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary (Microsoft.Build.BackEnd.Logging.ILoggingService loggingServiceForEvaluation, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x00035] in <b695b16788dd418cbe8b4d98f7a92ff3>:0
at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary (Microsoft.Build.BackEnd.Logging.ILoggingService loggingServiceForEvaluation, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x00000] in <b695b16788dd418cbe8b4d98f7a92ff3>:0
at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary (Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x00007] in <b695b16788dd418cbe8b4d98f7a92ff3>:0
at Microsoft.Build.Evaluation.Project.Initialize (System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.String toolsVersion, System.String subToolsetVersion, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x00126] in <b695b16788dd418cbe8b4d98f7a92ff3>:0
at Microsoft.Build.Evaluation.Project..ctor (System.String projectFile, System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.String toolsVersion, System.String subToolsetVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x00093] in <b695b16788dd418cbe8b4d98f7a92ff3>:0
at Microsoft.Build.Evaluation.Project..ctor (System.String projectFile, System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.String toolsVersion, System.String subToolsetVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings) [0x00000] in <b695b16788dd418cbe8b4d98f7a92ff3>:0
at Microsoft.Build.Evaluation.Project..ctor (System.String projectFile, System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.String toolsVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings) [0x00000] in <b695b16788dd418cbe8b4d98f7a92ff3>:0
at Microsoft.Build.Evaluation.Project..ctor (System.String projectFile, System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.String toolsVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection) [0x00000] in <b695b16788dd418cbe8b4d98f7a92ff3>:0
at Microsoft.Build.Evaluation.ProjectCollection.LoadProject (System.String fileName, System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.String toolsVersion) [0x000f7] in <b695b16788dd418cbe8b4d98f7a92ff3>:0
at Microsoft.Build.Evaluation.ProjectCollection.LoadProject (System.String fileName, System.String toolsVersion) [0x00000] in <b695b16788dd418cbe8b4d98f7a92ff3>:0
at OmniSharp.MSBuild.ProjectLoader.EvaluateProjectFileCore (System.String filePath) [0x0003f] in <2f3a2b5c7c0c433db9c1ecf376f496aa>:0
at OmniSharp.MSBuild.ProjectLoader.BuildProject (System.String filePath) [0x0000d] in <2f3a2b5c7c0c433db9c1ecf376f496aa>:0
at OmniSharp.MSBuild.ProjectFile.ProjectFileInfo.Load (System.String filePath, OmniSharp.MSBuild.ProjectIdInfo projectIdInfo, OmniSharp.MSBuild.ProjectLoader loader) [0x00015] in <2f3a2b5c7c0c433db9c1ecf376f496aa>:0
at OmniSharp.MSBuild.ProjectManager+<>c__DisplayClass29_0.<LoadProject>b__0 () [0x00000] in <2f3a2b5c7c0c433db9c1ecf376f496aa>:0
at (wrapper delegate-invoke) System.Func`1[System.ValueTuple`3[OmniSharp.MSBuild.ProjectFile.ProjectFileInfo,System.Collections.Immutable.ImmutableArray`1[OmniSharp.MSBuild.Logging.MSBuildDiagnostic],OmniSharp.MSBuild.Notification.ProjectLoadedEventArgs]].invoke_TResult()
at OmniSharp.MSBuild.ProjectManager.LoadOrReloadProject (System.String projectFilePath, System.Func`1[TResult] loader) [0x0001b] in <2f3a2b5c7c0c433db9c1ecf376f496aa>:0
Ubuntu 19.10, vscode 1.40.0, Elemental.JsonResource 0.2.0, ms-vscode.csharp 1.21.7, dotnet 3.0.100
Build fails with the following project layout:
...
<ItemGroup>
<StaticResourceFolder Include="data/Example"/>
</ItemGroup>
...
project-root/data/Example/
The json files simply have {}
inside them
MSBuild version 17.4.0+18d5aef85 for .NET
Determining projects to restore...
All projects are up-to-date for restore.
/home/sam/.../obj/Debug/net7.0/SylvanStaticResources/data/Example.g.cs(68,25): error CS0756: A partial method may not have multiple defining declarations [/home/sam/.../my-project.csproj]
/home/sam/.../obj/Debug/net7.0/SylvanStaticResources/data/Example.g.cs(60,2): error CS0579: Duplicate 'global::System.Diagnostics.DebuggerNonUserCode' attribute [/home/sam/.../my-project.csproj]
/home/sam/.../obj/Debug/net7.0/SylvanStaticResources/data/Example.g.cs(68,25): error CS0111: Type 'Example.Subfolder' already defines a member called 'PreProcess' with the same parameter types [/home/sam/.../my-project.csproj]
/home/sam/.../obj/Debug/net7.0/SylvanStaticResources/data/Example.g.cs(70,19): error CS0111: Type 'Example.Subfolder' already defines a member called 'Process' with the same parameter types [/home/sam/.../my-project.csproj]
Build FAILED.
/home/sam/.../obj/Debug/net7.0/SylvanStaticResources/data/Example.g.cs(68,25): error CS0756: A partial method may not have multiple defining declarations [/home/sam/.../my-project.csproj]
/home/sam/.../obj/Debug/net7.0/SylvanStaticResources/data/Example.g.cs(60,2): error CS0579: Duplicate 'global::System.Diagnostics.DebuggerNonUserCode' attribute [/home/sam/.../my-project.csproj]
/home/sam/.../obj/Debug/net7.0/SylvanStaticResources/data/Example.g.cs(68,25): error CS0111: Type 'Example.Subfolder' already defines a member called 'PreProcess' with the same parameter types [/home/sam/.../my-project.csproj]
/home/sam/.../obj/Debug/net7.0/SylvanStaticResources/data/Example.g.cs(70,19): error CS0111: Type 'Example.Subfolder' already defines a member called 'Process' with the same parameter types [/home/sam/.../my-project.csproj]
0 Warning(s)
4 Error(s)
Is there a way to integrate this into the learn.microsoft.com method of using a localizer?
JSON schemas can be used by software to understand the object Type of a JSON file.
They can also be used via editor extensions to provide completion suggestions.
A JSON file can use a "$schema" keyword to notify the JSON reader of a local or remote JSON schema via a relative or full path. This means a schema file can be maintained in this repo or another, packaged with the NuGet package, or even generated at build-time.
If "$schema" is not present in a JSON file, the reader or language server checks schemastore.org for a schema that matches the current filename. There seems to already be a schema for *.resjson files, but this may be unrelated to this project.
First, thanks for this package -- it's very useful.
I have a hierarchy of SQL files that I am trying to process using the StaticResourceGenerator. When I ran it, it was ignoring a bunch of folders I had because they were nested. However, if I had at least one file at each level, it worked and I just ignored the bogus "placeholder" file. If I am reading the repo correctly, you have the call to Directory.EnumerateDirectories (line 144) inside of the call to EnumerateFiles (line 122). So if there are no files, it will skip attempting to look for any folders and move on. Can the EnumerateDirectories be put outside the file loop so that we can have nested folders without having to have at least one file at each level? I am using the nesting to build up the namespace, so I don't want a file at every single folder level.
Thanks,
Bryan
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.