.Net Core 1.0 Relative Project Dependencies Not Found - .net-core

I have the project structure:
/src
- common
- common-x
+ project.json
- module-a
- project-a
+ project.json
- project-a-tests
+ project.json
+ global.json
I'm trying to include the common-x project using relative file paths in the global.json file.
The global.json file in the module-a directory is as follows:
{
"projects": [
"project-a",
"project-a-tests",
"../common/common-x"
]
}
and the project.json file in project-a is
{
// Default config options are also in this...
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.1",
"type": "platform"
},
"common-x": {
"target": "project"
}
}
}
project-a-tests has no problem referencing project-a since they are in the same directory, but project-a can't find the common-x project. I receive a "Unable to resolve ..." error from dotnet restore.
I have tried using absolute paths but that doesn't work either. The closest solution so far is to use symlinks but that is not preferable.
Note: This is all being run on Ubuntu 16.04.

You should only need to specify top level folders in your global.json file, since sub-folders will be scanned automatically. Global.json reference.
So your global.json should look like this.
{
"projects": [ "src" ]
}
If you are still getting any dependencies issues that might related to compatibility problems between projects/modules, however I would need to see the exact output you are getting to troubleshoot that.
UPDATE
A few tips that might be useful:
Delete old project.json.lock files
Add a .sln solution file if you don't have one created.
UPDATE 2
As per your comment, the working solution was to move global.json into src folder, and list your top-level folders in the projects array.

Related

How to register a local directory as a composer package

I can't figure out how to register a local directory as a composer package. I found lots of information about registering a local folder that is either a git repository or a composer package or even a zip hosted somewhere.
However I want to register a folder on my local machine, residing in the same repository as my wordpress installation (using wordplate) that is neither a git repository nor a composer package as it doesn't contain any composer.json.
What I try at the moment is to register it like this under repositories:
{
"type": "package",
"package": {
"name": "local/contact-form-7-mailchimp-extension",
"type": "wordpress-plugin",
"version": "dev-master",
"source": {
"type": "path",
"url": "resources/plugins/contact-form-7-mailchimp-extension",
"reference": "master"
}
}
}
Add "local/contact-form-7-mailchimp-extension": "*" under "require",
add "local/contact-form-7-mailchimp-extension" in "public/plugins/{$name}" under "extras" > "installer-paths".
Running composer install however doesn't install it and gives no information at all. Don't even know if it found the url or not..
Is it even possible to install a local directory like that?
You can use the path repository to install packages from a different path into your project.
However I want to register a folder on my local machine, residing in the same repository as my wordpress installation (using wordplate) that is neither a git repository nor a composer package as it doesn't contain any composer.json.
For this to work, your plugin inside the folder will need a composer.json, though. This is necessary for composer to recognize this folder as a package in the first place. Fortunately, it can be as simple as this:
{
"name": "local/contact-form-7-mailchimp-extension",
"description": "My Contact Form-extension using mailchimp",
"type": "wordpress-plugin",
"version": "dev-master"
}
Assuming the plugin is in the directory resources/plugins/contact-form-7-mailchimp-extension, you can now register this path as a repository path, meaning composer will look inside this folder for a composer.json and when your wordpress-project requires the provided package it will (by default) be symlinked into vendor.
The wordpress project's composer.json then needs these entries (the options for the repository are the defaults and can be left out, this is just to show how to disable symlinking, should you need that):
{
...,
"repositories": [
{
"type": "path",
"url":"resources/plugins/contact-form-7-mailchimp-extension",
"options": {
"symlink": true
}
}
],
"require": {
"local/contact-form-7-mailchimp-extension": "dev-master",
...
}
}
When composer installs the package, it should tell you where it installed it from, i.e. you should find the path from the repository in there.

How to create own autogenerated files by composer

I'm working on project in Symfony 2. In this project, there's file named parameters.yml.dist which is base for composer to create parameters.yml. We have two environments (prod, dev), each one has own parameters file (for dev it's parameters_dev.yml).
My problem is that, some users and servers have different dev configuration, but file exists in repository - that makes deployment and work a little bit uncomfortable.
Is there a way to make that parameters_dev.yml file be autogenerated same as parameters for prod? I tried to create this *.dist file but that's not worked, maybe I have to do something else?
I found the solution. Parameters are managed by this bundle: https://github.com/Incenteev/ParameterHandler
That's how part of my composer.json file looks now:
"incenteev-parameters": [
{
"file": "app/config/parameters.yml"
},
{
"file": "app/config/parameters_dev.yml"
}
],
Funny, I searched composer.json in first place but didn't found anything.

ASP .NET 5 - grunt task to copy files from node modules to wwwroot

I have a simple ASP .NET 5 empty project - with npm and grunt installed.
I've used npm to install a few client-side libraries, at present located in the node_modules directory directly under my ASP .NET project.
I want to copy the relevant files (for example, jquery.min.js) from the node_modules folder into the wwwroot folder.
It's unclear to me how to use grunt to do this - as each node module has it's own dependency tree, and there doesn't seem to be any consistency in the file structure from package to package.
I could write a grunt task explicitly for each client side library I use, but in that case I may as well download everything manually and place the files where I need them manually, avoiding npm all together.
I know I could use bower, which has a flat dependency tree - which is probably the root I should go down - but I've read a few articles saying "there's no need for bower - npm can do it all" and therefore I would like to know if there's a way to do this purely with npm.
Is there a way? Or is the "npm can do it all" statement aimed at projects that will require the components directly from the node_modules?
TL DR; Is bower a better fit than npm for ASP .NET 5 projects with separation of source and build files, and if not, what's the recommended way of doing it purely with npm?
I don't fill me professional in grunt, but I use it myself and I think that I can explain you how one can use it corresponds to your requirements.
First of all you should add "New Item" to your project, choose "Client-Side" and "NPM Configuration file" to add package.json to the the project (in the same directory where you have project.json). I suppose you have already created the file, but the existence of the file is important for grunt too. Then you adds some dependencies, which you need on the client-side to "dependencies" part of package.json and add at least grunt and grunt-contrib-copy to "devDependencies" part. An example of the file you will see below
{
"version": "1.0.0",
"name": "ASP.NET",
"private": true,
"dependencies": {
"font-awesome": "^4.5.0",
"jquery": "^1.11.3"
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-clean": "^0.7.0",
"grunt-contrib-copy": "^0.8.2"
}
}
Now you should add "Grunt Configuration File" in the same way like you added "NPM Configuration file". You will create gruntfile.js (in the same directory where you have project.json). Finally you should fill gruntfile.js with more helpful code. For example the code
module.exports = function(grunt) {
grunt.initConfig({
clean: ["wwwroot/font-awesome/", "wwwroot/jquery*.*"],
copy: {
main: {
files: [
{
src: "node_modules/font-awesome/css/*",
dest: "wwwroot/font-awesome/css/",
expand: true,
filter: "isFile",
flatten: true
},
{
src: "node_modules/font-awesome/fonts/*",
dest: "wwwroot/font-awesome/fonts/",
expand: true,
filter: "isFile",
flatten: true
},
{
src: "node_modules/jquery/dist/*",
dest: "wwwroot/",
expand: true,
filter: "isFile",
flatten: true
}
]
}
}
});
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.registerTask("all", ["clean", "copy"]);
grunt.registerTask("default", "all");
};
registers two tasks: clean and copy and the aliases all and default. You can select gruntfile.js file in the solution explorer, open context menu and choose "Task Runner Explorer". You will see all defined tasks. The task with the name "default" will be executed if you execute grunt without parameters (without the task name) in the command line.
Now you can choose some task and run it. You can choose some task, click right mouse button to open context menu and check "After Build" in "Bindings":
Now the task will be executed every time when you build the project. You can click optionally "V" button on the left side to see verbose information from the executed tasks.
I hope it's already the main information which you need. Many other helpful information about plugins grunt-contrib-clean, grunt-contrib-copy, grunt-contrib-jshint, grunt-jscs, grunt-newer and many other you will find yourself. One official place of ASP.NET 5 documentation should be mentioned. It's the place.
P.S. You asked additionally about the usage of bower. I find both npm and bower not perfect, but still very practical. I would prefer to hold full control over the dependencies and especially about the data, which will be copied under wwwroot. Thus I change the content of .bowerrc file from { "directory": "wwwroot/lib" } to { "directory": "bower_components" } and I use grunt to copy the required data from bower_components in the same way like I do this with files from node_modules. See the article for more details. In other words I use packages published only in bower repository in the same way like I use npm packages.

Exclude folders on publish project using "dnu publish"

How can I exclude folders from wwwroot using "dnu publish" command.
Example: in my project exists many folders
I need exclude wwwroot/lib and wwwroot/source.
I´m using clr 1.0.0-beta7-12302
The wwwroot folder is treated differently. It is called a webroot. The content in this folder doesn't go through globbing during publish (see here). It is recommended that source code and output are put out of the webroot.
Do you have scenario that you have to store source codes and binaries in this folder?
Within the Project.json file it looks like you can specify which files you would like to exclude when publishing using the publishExclude property in the sources section. https://github.com/aspnet/Home/wiki/Project.json-file#sources
I too was looking for a way to exclude the wwwroot/lib directory from being published and I came across this post from Scott Hanselman. In the post he shows how to change the storage location of bower components (ex. from wwwroot/lib to /bower_components).
For me this removed the wwwroot/lib directory, so these libraries are no longer published. I just thought I would throw this here in case someone may be able to use it.
MS dropped support for bower_components and node_modules exclusion in .NET Core 1.0 RTM. The best I was able to achieve was just to exclude the /src folders so the publish size could be reduced.
Project.json (Excluding Bower Components SRC files)
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views/**",
"appsettings.json",
"web.config"
],
"exclude": [ "wwwroot/**/src/**" ]
}

Asp.net vnext global.json with 2 levels folders is not working

I'm using visual studio 2015 preview.
My solution structure is like this
/Solution
Dummy.sln
/src
/config
/app
Library1.kproj
/Web.kproj
/db
/tests
unitTests.kproj
My global.json file looks like this
{
"sources": [ "src" ]
}
My "Web project" successfully had a reference to "library project".
But my "unitTests project" fails to see the "library project" reference. Whenever I add a reference... it mistakenly resolves to:
C:\Users\UserAccount\.kpm\packages\Library1\1.0.0
Which is wrong.
I tried few options ... none worked. Does global.json support folder paths ?
{
"sources": [ "src", ".\tests", ".\app" ]
}
Any solutions other than changing the solution structure?
{
"sources": [ "src" ]
}
is correct. I've had this issue before. You need to look at the actual folder structure in explorer. The sln file and global.json file should be at the same level. You should NOT have a folder called "src", It should be like this ON DISK:
Project folder
- Something.Web folder
- Something.Tests folder
- sln file
- json file
then in the actual sln in VS, you would have it the way you have setup already, with the src 'folder'

Resources