I am currently working on a .NET Core library that I am going to use as a NuGet package in another project.
I have been able to successfully package the project using the "dotnet pack" command in the project directory, and upload that package to MyGet.
I would prefer to automate this process of pushing the NuGet package by using the "nuget push" command.
My issue is that the "scripts" property defined in the project.json file does not seem to be executed on pack or build. I expected that these scripts would be executed when the corresponding event occurs, but they seem to have no effect as I do not see anything output to console when I build, with or without he verbose tag.
I understand that MyGet is able to update a package feed based on a Git repository, but I would like to understand if there is some issue with executing a script currently using a project.json. Ideally I want to use the nuget push command after pack successfully executes.
Here is my project.json file :
{
"version": "0.0.1",
"scripts": {
"postbuild": [ "echo build" ],
"prebuild": "echo build",
"postpack": "echo build",
"postpublish": "echo build",
"postrestore": "echo build",
"prepack": "echo build",
"prepare": "echo build",
"prepublish": "echo build",
"prerestore": "echo build"
},
"dependencies": {
"NETStandard.Library": "1.5.0-rc2-24027"
},
"frameworks": {
"netstandard1.5": {
}
},
"buildOptions": {
"allowUnsafe": false,
"debugType": "portable",
"emitEntryPoint": false,
"xmlDoc": false
},
"commands": { },
"packOptions": {
"files": {
"include": "%project:Directory%/bin/release/*.nupkg"
}
},
"configurations": {
"Debug": {
"buildOptions": {
"define": [ "DEBUG", "TRACE" ]
}
},
"Release": {
"buildOptions": {
"define": [ ]
}
}
}
}
RC2 replaced prebuild and postbuild with precompile and postcompile.
You can use the postcompile to automatically generate the nupkg and to push the package to a nuget server using
"scripts": {
"postcompile": [
"dotnet pack --no-build",
"\"%project:Directory%\\..\\..\\nuget.exe\" push \"%project:Directory%\\bin\\%compile:Configuration%\\%project:Name%.%project:Version%.nupkg\" -source nugetserver -ApiKey key"
]
}
This will automatically call the dotnet pack using the project.json file that exists in the project directory. Then it will push the nuget package to the specified nuget server.
Unfortunately there is no variable to specifiy the build configuration therefore in the above path you will have to manually change it when you switch between debug and release configuration.
The above uses %compile:Configuration% to specify the current build configuration.
The answer to the current build configuration comes from
How to run scripts based on solution configuration in ASP.NET Core RC2
Visual Studio 2017
In Visual Studio 2017 you can use the dotnet nuget push command by editing the csproj file and using the following command
<Target Name="PushPackage" AfterTargets="Pack">
<Exec Command="dotnet nuget push "$(MSBuildProjectDirectory)\bin\$(Configuration)\$(AssemblyName).$(Version).nupkg" -s nugetserver -k apikey" />
</Target>
Related
In my project I am using expo-sdk:43 along with expo-updates.
I have setup the channel property in eas.json file.
{
"cli": {
"version": ">= 0.52.0"
},
"build": {
"development": {
"developmentClient": true,
"distribution": "internal",
"channel":"dev"
},
"preview": {
"android": {
"buildType": "apk"
},
"channel":"preview"
},
"production": {}
},
"submit": {
"production": {}
}
}
I have tried to publish my updates through EAS update, but it is not working and the app is not receiving any update. I have tried to do an apk build for the application, and tried to get the output of Updates.Channel and it is outputting as undefined.
eas build -p android --profile --preview
eas update --branch preview --message "update"
But, when I build the app, the build is successful, in the eas logs I can see that it shows that channel property has also been configured.
Can someone please help what might be the possible issue in this case?
I have also tried to do the same steps with an expo-init command (But with expo sdk:47) and minimal app setup and it is working as expected.
Description:
During the deploy of firebase hosting, I received an error stating that 0 files were found. I have included my firebase.json file for reference.
Steps to reproduce:
Run the command firebase deploy --only hosting
Observe the error message stating that 0 files were found
Expected result:
The firebase hosting should be successfully deployed with the specified files.
Actual result:
An error is thrown stating that 0 files were found.
+ hosting: Finished running predeploy script.
i hosting[hosting-project]: beginning deploy...
i hosting[hosting-project]: found 0 files in hosting
+ hosting[hosting-project]: file upload complete
i hosting[hosting-project]: finalizing version...
+ hosting[hosting-project]: version finalized
i hosting[hosting-project]: releasing new version...
+ hosting[hosting-project]: release complete
+ Deploy complete!
Notes:
I have double-checked the file path in the firebase.json file and it
appears to be correct.
I have tried rerunning the deploy command multiple times with the same result
I have also tried deploying a
different project with the same firebase.json file, but the issue
persists.
In my firebase.json file, I am not targeting the dist folder directly because I am using the predeploy script to run npm run lint and npm run build before the deployment. However, I am not ignoring the dist folder with !dist% and !dist/*, which means I am not excluding it from the deployment.
Attached files:
firebase.json
{
"firestore": {
"port": "8080"
},
"functions": [
{
"source": "functions",
"codebase": "default",
"ignore": [
"node_modules",
".git",
"firebase-debug.log",
"firebase-debug.*.log"
],
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
}
],
"hosting":{
"public":"hosting",
"ignore": [
"*",
"!dist/",
"!dist/*",
],
"rewrites":[
{
"source":"**",
"destination":"dist/index.html"
}
],
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint",
"npm --prefix \"$RESOURCE_DIR\" run build"
]
}
}
I found a solution to resolve the issue of "0 files found" during the deploy of firebase hosting. It may not be the most elegant solution, but it does work. In the "predeploy" section of the hosting configuration, I added ".." at the end of the "npm run lint" and "npm run build" commands to go back to the root folder:
"npm --prefix \"$RESOURCE_DIR\\..\" run lint",
"npm --prefix \"$RESOURCE_DIR\\..\" run build"
This allowed me to target the dist folder directly in the hosting configuration, as specified in the official documentation. Here is the modified hosting configuration:
"hosting":{
"public":"hosting/dist",
"ignore": [
"**/.*",
"**/node_modules/**"
],
"rewrites":[
{
"source":"**",
"destination":"/index.html"
}
],
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\\..\" run lint",
"npm --prefix \"$RESOURCE_DIR\\..\" run build"
]
}
I hope this helps anyone else who may be experiencing the same issue.
I'm using yarn v1.22 and yarn workspace for building my application as a monorepo. Here is the package.json for our component library package. I want to use publishConfig to override the main field when I do npm publish or yarn publish. But when I tried to run those commands, the main field is no changed. Can anyone share some suggestions? Thanks.
{
"name": "components",
"private": false,
"version": "0.1.2",
"main": "src/index.ts",
"files": [
"dist"
],
"publishConfig": {
"main": "dist/index.js"
}
}
I had problems to get an electron project using webpack to get packed as an MSI installer. I came around electron-wix-msi package. It's a wrapper for the great WIX toolkit. The advantage is, that it is more Windows like.
However, the docs are unclear and not sufficient to get it immediately running. Finally I got it and want to share the steps here.
I used TypeScript for development and got a working installation for all parts, including MSI.
This is for Windows users only. The process describes the creation of an Windows-Installer (MSI).
Install Wix Toolkit as mentioned in docs
Add path to candle.exe and light.exe, which is "C:\Program Files (x86)\WiX Toolset v3.11\bin" to path variable. Check that if you enter "candle" at prompt the candle.exe executes.
Create installation file as make-msi.ts in folder build (just a suggestion, any path will do it):
import * as msi from 'electron-wix-msi';
import * as path from 'path';
// Step 1: Instantiate the MSICreator
const msiCreator = new msi.MSICreator({
appDirectory: path.resolve('release/win-unpacked'), // result from electron-builder
description: 'Some text',
exe: 'MyExe',
name: 'MyExe',
manufacturer: 'Joerg Krause',
version: '0.5.0',
language: 1033,
arch: 'x86',
outputDirectory: path.resolve('release/msi/')
});
async function createMsi() {
// Step 2: Create a .wxs template file
await msiCreator.create();
// Step 3: Compile the template to a .msi file
await msiCreator.compile();
}
console.log('Invoke MSI Builder');
createMsi();
release/win-unpacked is the output from electron-builder.
Add tsconfig.json with appropriate settings in same folder build:
{
"compilerOptions": {
"target": "es2015",
"module": "commonjs",
"moduleResolution": "node",
"resolveJsonModule": true,
"sourceMap": true,
"lib": [
"es2018",
"es5",
"dom"
],
"experimentalDecorators": true,
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"removeComments": false,
"outDir": "js",
"typeRoots": [
"../node_modules/#types",
]
}
}
Check both files in the folder build
Add npm run command like this to your package.json:
cd build && tsc && cd .. && node build/js/make-msi.js
My whole scripts block looks like this:
"scripts": {
"dev": "tsc win.ts --outDir ./dist && cross-env NODE_ENV=dev && npm run prev",
"build": "rimraf ./dist && webpack",
"start": "rimraf ./dist && webpack && electron .",
"prev": "electron .",
"test": "jest",
"msi": "cd build && tsc && cd .. && node build/js/make-msi.js",
"pack": "npm run build && rimraf ./release && build --dir && npm run msi",
"dist": "build"
}
This compiles the TypeScript into ES and executes the script with npm run msi. After a while you have your MSI.
Also, I had much more success using electron-builder instead of electron-packager.
For those who want to get more, my setup is as this:
I write my apps with HTML 5 API (no React/Angular or so). I can really recommend this for small and medium apps.
I use TypeScript 3 for all coding stuff
I use SASS for all CSS stuff
Using webpack to compile, optimise and pack
I use electron-builder to bundle
I use the process described above to make a Windows package.
Great tutorial. Your tsconfig.json lacks one line to get "tsc" work, otherwise you will get an error like error TS2307: Cannot find module 'path':
"types": ["node"],
I am using npm precommit hook, but it is not stopping a file with issues to be committed, nor am I getting the message "Pre commit checks" when I try to commit a file.
Package Json:
{
"name": "myfolder",
"version": "1.0.0",
"description": "",
"main": "",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 0",
"precommit-msg": "echo 'Pre-commit checks...' && exit 0",
"lint": "csslint global/css"
},
"author": "SR",
"license": "ISC",
"dependencies": {
"csslint": "^1.0.4",
"jshint": "^2.9.4",
"pre-commit": "^1.2.2"
},
"pre-commit": [
"precommit-msg",
"lint"
],
"devDependencies": {
"pre-commit": "^1.2.2"
}
}
Please, make sure that your 'package.json' file is in the same folder, where '.git' folder is (where git repository was initialized). When you install 'pre-commit' package, 'pre-commit' file should appear under '.git/hooks/'.
Just FYI I had this issue because the pre-commit file was missing in the hooks folder.
Running npm i pre-commit --save-dev again created the file and solved it for me.
Have't managed to implement it with few "pre-commit" NPM modules (#fastify/pre-commit, monorepo-staged-precommit) so implemented it "manually" with adding tools/pre-commit.sh file into repo with content like:
#!/bin/sh
DIR='web'
echo "Pre-commit actions (NPM tests for $DIR)..."
cd $DIR && npm run test
and updating package.json with:
"scripts": {
"test",
"install-precommit": "cp ../tools/pre-commit.sh ../.git/hooks/pre-commit"
This solution has some limitations (like instead of automatic installation need to ask somewhere in "README" about npm run install-precommit and I'm not sure how it would work on Windows especially without Git Bash) but it worked for me.
Notes:
Other pre-commit NPM packages either didn't work as well or asked for NVM and other extra tools which I don't want devs to install for such small task.
pre-commit.sh may has any name and don't be executable - "install-precommit" task and git care about.