Can't get NLog to throw an exception or write a log (works on my machine) - asp.net-web-api2

I have a .Net webapi running on my workstation (Win10, IIS 10) and everything works like a charm. However when I push it to our production box (Win7, IIS 6) NLog will neither write a log nor throw an exception. My NLog.config is here:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
throwExceptions="true"
>
<targets async="true">
<target
name="logfile"
xsi:type="File"
layout="${date}|${level:uppercase=true}${message}"
fileName="C:\inetpub\wwwroot\myapp\App_Data\webapi.log"
/>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="logfile" />
</rules>
</nlog>
No matter what I set the fileName property to, it will not write a log on the Win7 box and does not throw an exception. I would see the exception in the Event Viewer under Windows Logs -> System, correct?
Note that I do not have administrative access to the target Win7 box but have enough elevated privileges to write files to wwwroot.
What am I missing? An exception or some type of error would be nice.
Edit: in fact it does NOT work at all on IIS10/Win10 though it does work fine when running in Visual Studio (IIS Express?). Both Visual Studio and IIS Manager are being run "as administrator". No logfile output, no exceptions, nothing in the Event Viewer. ???

There is a NLog Troubleshooting guide on https://github.com/NLog/NLog/wiki/Logging-Troubleshooting
When you get no log output from NLog, this can be because of the following reasons:
NLog cannot find the configuration file. This can happen when the NLog.config file is configured with Build Action = None or Copy to Output Directory = Do not copy in Visual Studio. Set Build Action = Content and "Copy to Output Directory = Copy if newer to fix this)
Is your configuration file valid XML?
Logging rules are incorrect or no rules are defined
Application tracing code is incorrect.
There is a runtime problem with the target (such as missing permissions)
Logs are written to a different location.
Also you could enable the internal log: https://github.com/NLog/NLog/wiki/Internal-logging
Update: if your internal log isn't working, then it would be difficult to diagnose the issue.
You could enable throwing exceptions from code:
LogManager.ThrowExceptions = true;
LogManager.ThrowConfigExceptions = true;

Related

Can not publish since moving to VS 2019

I have recently uninstalled VS 2017 and installed VS 2019.
When I publish my website via Web Deploy, if fails with 2 error messages
Failed to load publish certificate dialog due to error of Object reference not set to an instance of an object. MyWebsite.Ui
Web deployment task failed. (Connected to the remote computer ("example.com") using the specified process ("Web Management Service"), but could not verify the server’s certificate. If you trust the server, connect again and allow untrusted certificates. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_CERTIFICATE_VALIDATION_FAILED.)
I'm totally clueless on how I can solve this...
Edit
As per the comments, there is a question which is the same, but that question is about Azure. I'm not connecting to anything Azure related. I'm not saying that this makes my questions unique, more that I don't have the knowledge to understand if the cause/solution is the same. Deploying to Azure from Visual Studio fails when connecting
If you trust the server, then you can simply ignore the warning/error by editing the publish file directly
https://stackoverflow.com/a/33662970/3252861
Open the publish profile file (.pubxml) inside /Properties/PublishProfiles in a text editor
Inside the PropertyGroup element, set AllowUntrustedCertificate to True (AllowUntrustedCertificate> True /AllowUntrustedCertificate>) or add it if it doesn't exist
Set UsePowerShell to False (False).
I didn't do the 3rd point, so I guess I either have previously or didn't need it
Now we can follow the advice on https://developercommunity.visualstudio.com/content/problem/484286/publish-fails-to-iis-using-msdeploy-webdeploy.html and actually add the following 2 entries
<UseMSDeployExe>True</UseMSDeployExe>
<AllowUntrustedCertificate>True</AllowUntrustedCertificate>
It should be pointed out that some have reported you only need to use one of those two:
<AllowUntrustedCertificate>True</AllowUntrustedCertificate>
So, the start of the pubxml XML file now looks like
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<UseMSDeployExe>True</UseMSDeployExe>
<AllowUntrustedCertificate>True</AllowUntrustedCertificate>
<WebPublishMethod>MSDeploy</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>True</ExcludeApp_Data>
<MSDeployServiceURL>domain</MSDeployServiceURL>
<DeployIisAppPath>name</DeployIisAppPath>
<RemoteSitePhysicalPath />
…
…
In your /Properties/PublishProfiles/xxxxxx.Settings.pubxml file, add the following two lines
<UseMSDeployExe>True</UseMSDeployExe>
<AllowUntrustedCertificate>True</AllowUntrustedCertificate>
I know this is old, but I did find a different solution that worked for me (after trying to create/upload certificates; reset publishing profiles, etc.)
If you have the nuget package MSBuild.Microsoft.VisualStudio.Web.targets installed in your project, it's old and that's what breaks it. Remove that package and your publish will work. No need to add the AllowUntrusted flat in your pubxml as long as your server IS trusted. (*ie Azure.)
I´m using VS 2019
Add the next lines into PropertyGroup node:
<UseMSDeployExe>True</UseMSDeployExe>
<AllowUntrustedCertificate>true</AllowUntrustedCertificate>
I am from the product team and I can confirm that this is the only property that needs to be set if the server certificate is untrusted.
<AllowUntrustedCertificate>True</AllowUntrustedCertificate>
Verify your code if there is any errors /C#/ Razor syntax, sometimes errors will not show in errors window.
Same problem here. I attempted to delete the obj file folder figuring that was the problem. And it was, I had two pdf files in them that wouldn't delete being they required Admin privilege's to delete. I used the command prompt utility to go in and delete them and then did a rebuild and published with no issues.

asp.net core 2.1 HTTP Error 502.5

When I am trying to run my solution I am getting In the browser:
HTTP Error 502.5 - Process Failure
Debugging stops almost immediately after it starts and there is no error message inside visual studio.
In the output window this is the only message:
The program '[30700] dotnet.exe' has exited with code -2147450730 (0x80008096).
The project was working fine, I just installed a nuget package and this started happening. I tried deleting it and removing the package cache but it still happens.
Event viewer shows error with IIS Express AspNetCore Module.
Application 'MACHINE/WEBROOT/APPHOST/PROJECTNAME' with physical root 'E:\path\ProjectName\' failed to start process with commandline 'e:\program files (x86)\microsoft visual studio\2017\community\common7\ide\extensions\microsoft\web tools\projectsystem\VSIISExeLauncher.exe -argFile "C:\Users\username\AppData\Local\Temp\tmp49E1.tmp"', ErrorCode = '0x80004005 : 0.
I am a bit lost as there is no error to go on.
Any ideas?
Well! This is due to appropriate .NET Core SDK missing problem. Your project's package versions are higher than the SDK version installed on your machine.
Download the latest version v2.1.401 (at the time of that answer) from here: Download .NET Core SDK and install it.
Now restart your computer and run the project again.
Hope your problem will be solved!
Although it was already answered, I'll post here my solution for the same problem (HTTP Error 502.5 when starting my webapp on Asp.NET CORE 2.1, error code 0x80004005) that has a different reason, as reference of another possibility.
Short Answer:
If the name of the application has a space (character) on it, the current version of Visual Studio (15.8.9) has a bug, that doesn't include quotes to make it a literal string argument on the moment of execution (through commandline) on the web.config file, generated when publishing your webapp.
Example:
web.config generated by Visual Studio (version 15.8.9 - Date: 2018-Nov-05):
[...]
<aspNetCore processPath="dotnet" arguments=".\My Web App.dll" stdoutLogEnabled=... />
[...]
web.config with correct quotation:
[...]
<aspNetCore processPath="dotnet" arguments='".\My Web App.dll"' stdoutLogEnabled=... />
[...]
You can see on the attribute arguments on the second example, that I included (manually) single quotes, making it pass the full string ".\My Web App.dll" as the argument on the moment of execution.
Detailed Answer:
Every time I update my Visual Studio for a newer SDK (and using the most recent version of Asp.net Core in my application) it give me the Http Error 502.5, IF i do not update the runtime libraries on my server too. So, obviously the first thing that I did was update the runtime libraries on the server (which always solved this problem to me), but this time it didn't worked.
So, starting to troubleshoot, I just tried to start my webapp from the command line (prompt), and it started perfectly.
So, I knew that there was something wrong with the way my webapp was being started. The starting configuration (on asp.net core) is in the web.config file.
[...]
<aspNetCore processPath="dotnet" arguments=".\My Web App.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
[...]
In Asp.net Core, the web application is started/executed from the commandline (prompt) on windows, by IIS (i'm strictly speaking of common scenario).
Till now, it always had a .exe file between the published files, that started the whole thing, and this was the file called by IIS Module through commandline.
Since Asp.net CORE 2.1 (and some minor update that i don't know exactly), there is no .exe file, and the PATH of Web App is passed by argument. So you have the command that is dotnet and a argument to this command that is specified as argument attribute, on the web.config file. (as shown in the example above)
Taking a look on my published web.config file, you can see the processPath and arguments attributes. In the previous test, I knew that dotnet was a recognized command, since I was able to start my webapp on windows command prompt. Then, looking carefully the arguments attribute, I saw that there was no (surrounding) quotation for the value, that contained space characters in it.
So in the startup of my webapp, instead the dotnet command receive the full path .\My Web App.dll, it was receiving 3 different arguments: .\My , Web , App.dll .
Since the value of the arguments attribute is passed through commandline, it has to have quotation when passed to the commandline, becoming a literal string.
So I mannualy added the necessary surrounding quotation on the arguments attribute value, in the web.config file, and my web app started to work perfectly!
To see the example of the bug, and how to correct it, just take a look on the "Short Answer" examples.
Other useful information (for Asp.net Core 2.0 and up, with Windows / IIS):
If you had a web application that was working, and is not anymore, giving the error 502.5:
It's probably a versioning problem of the runtime libraries. Your webapp is asking for newer asp.net core libraries, and your server doesn't have them yet.
Just update the runtime libraries on your server, and it should solve the problem. Download it from Microsoft (for the current version which is Asp.net Core 2.1, you can download from this link: https://www.microsoft.com/net/download/dotnet-core/2.1).
How to start your webapp manually, for better troubleshooting:
Open the windows command prompt, and try to execute the command dotnet. If it's not recognized, than you have to install (or repair) the asp.net core module and dependencies (google is your friend. Just search how to install asp.net core). Alternatively, you can check the Asp.net Core runtime libraries version with the command dotnet --version.
Once the dotnet command is recognized, you can start your webapp manually.
Navigate to the folder where is your webapp files (usually will be in inetpub, wwwroot, etc..). Then, locate the .dll file that is your application's assembly. Usually, it will have the name of your application (pretty easy, right!?). Then, execute it with the command dotnet ".\My Web App.dll".
Example:
If there is a error, you will see some useful information on the prompt window. If the webapp starts correctly, then it's some issue with the startup configuration, probably web.config file.
Another method to see more detailed information on asp.net core failure:
https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/troubleshoot?view=aspnetcore-2.1#application-event-log
Access the Application Event Log:
Open the Start menu, search for Event Viewer, and then select the Event Viewer app.
In Event Viewer, open the Windows Logs node.
Select Application to open the Application Event Log.
Search for errors associated with the failing app. Errors have a value of IIS AspNetCore Module or IIS Express AspNetCore Module in the
Source column.
Details of my issue:
When executing requests, the error presented was: HTTP Error 502.5 - Process Failure.
Looking on the Events Viewer (Windows Server), the information was: "Application ' ... My Web App' with physical root 'C:\ ... \ ... \' failed to start process with commandline 'dotnet .\My Web App.dll', ErrorCode = '0x80004005 : 1."
So my error code was: 0x80004005 , and the subcode was 1.
Hope it helps somebody :)

Launch IIS Express to run ASP.NET Core Apps

I wish to run my ASP.NET Core App by launching it from IIS Express using command line.
I stumbled across this article which says
So in fact Visual Studio silently adds the two environment variables
when launching IIS Express, so that ASP.NET Core related bits can be
injected.
LAUNCHER_ARGS: -debug -p “C:\Program Files\dotnet\dotnet.exe” -a “exec
\”C:\Users\lextm\documents\visual studio
2017\Projects\WebApplication2\WebApplication2\bin\Debug\netcoreapp1.0\WebApplication2.dll\””
-pidFile “C:\Users\lextm\AppData\Local\Temp\2\tmpFD6D.tmp” -wd “C:\Users\lextm\documents\visual studio
2017\Projects\WebApplication2\WebApplication2”
The tmp file in -pidFile “C:\Users\lextm\AppData\Local\Temp\2\tmpFD6D.tmp” can always change. How do I add LAUNCHER_ARGS as environment variable which will make it work even if the tmp file changes?
Let me know if there is any easier way to launch IIS Express to run ASP.NET Core Apps with command line or powershell scripts.
You are looking for [System.IO.Path]::GetTempFileName() method. It creates empty temp file on file system and returns its unique name.
I'm currently using the following PowerShell script to run my .NET Core 2.0 App:
$env:LAUNCHER_ARGS = "-p ""<path to dotnet.exe>"" -a ""exec \""<path to webapp main dll>\"""" -pidFile $([System.IO.Path]::GetTempFileName()) -wd ""<path to webapp root folder>"" -pr <project name>"
$env:LAUNCHER_PATH = "<path to VSIISExeLauncher.exe>"
& "<path to iisexpress.exe>" /config:"<path to applicationhost.config>" /site:"<webapp name>"
Placeholders (text within angle brackets) have to be filled with the corresponding values. You can find them out by running your project from Visual Studio and inspecting environment variables of iisexpress.exe process using Process Explorer as shown above in the link you provided.
In .NET Core 3 the solution to this problem has changed. Follow these steps.
1) The environment variables should now be:
LAUNCHER_ARGS=exec "C:\YourWebApiProject\bin\Debug\netcoreapp3.1\YourWebApiProject.dll"
LAUNCHER_PATH=C:\Program Files\dotnet\dotnet.exe
Change the first path to your dll path and ensure the .NET version in the path is correct. Note that there is no longer a need to create a temp file.
2) Ensure that both modules AspNetCoreModule and AspNetCoreModuleV2 are registered in the file .vs\{your solution name}\config\applicationhost.config as follows:
Under <system.webServer> <globalModules> add:
<add name="AspNetCoreModule" image="%IIS_BIN%\aspnetcore.dll" />
<add name="AspNetCoreModuleV2" image="%IIS_BIN%\Asp.Net Core Module\V2\aspnetcorev2.dll" />
Under <sectionGroup name="system.webServer"> add:
<section name="aspNetCore" overrideModeDefault="Allow" />
Under <location path="" overrideMode="Allow"> <system.webServer> <modules> add:
<add name="AspNetCoreModule" lockItem="true" />
<add name="AspNetCoreModuleV2" lockItem="true" />
It's also a good idea to make this change to the templates for this file which are located at %PROGRAMFILES%\IIS Express\config\templates\PersonalWebServer\applicationhost.config and %PROGRAMFILES(x86)%\IIS Express\config\templates\PersonalWebServer\applicationhost.config so that new VS solutions you create automatically get these changes to their configs. (Credit to this post)
3) Be mindful of whether you're using 32 or 64 bit IIS Express. (If you're on a 64 bit machine then 32 bit IIS Express = C:\Program Files (x86)\IIS Express, 64 bit = C:\Program Files\IIS Express) In my case, 32 bit had worked fine previously but after migrating to .NET Core 3 I had to use 64 bit or else the above modules wouldn't load.
I needed to run multiple .Net Core API endpoints at a time easily without popping open Visual Studio for each and every one of them. I ended up using answers here to build the following:
iisaspnet.bat:
#echo off
:: Args are like:
:: MobileApi
:: C:\Users\chris\Dropbox\Code\2017\VbaMeasureHcp\src\HCPMobileApi
:: MobileApi\bin\Debug\netcoreapp2.2\MobileApi.dll
:: .vs\MobileApp\config\applicationhost.config
setlocal
set PATH=%PATH%;C:\Program Files\IIS Express
set LAUNCHER_ARGS=exec %2\%3
set LAUNCHER_PATH=C:\Program Files\dotnet\dotnet.exe
iisexpress /site:%1 /config:"%2\%4"
:: Comment out line below to check for errors
exit
The first arg is the name of the Project - the name in Visual Studio (in some scenarios people go rogue and name their Project file one thing and the Project itself another thing - you want the Project name, not the file name, in this scenario).
The second arg is the root folder for third and fourth args.
The third arg is where to find the compiled Project DLL
The fourth arg is where to find the applicationhost.config that explains how to launch the site. As you'll see below, this is generally found in your .vs folder, but, where this exists can get a little crazy depending on how creative people get with organizing their Solution and Project folders. Generally the .vs folder is going to sit in the same folder as the .sln file, so it may be far from the Project folder/files.
This will be less helpful, but here's the batch file that kicks off the IIS Express windows, so you can see iisaspnet.bat in use:
start iisaspnet.bat MobileApi C:\Users\chris\Dropbox\Code\2017\VbaMeasureHcp\src\HCPMobileApi MobileApi\bin\Debug\netcoreapp2.2\MobileApi.dll .vs\MobileApp\config\applicationhost.config
start iisaspnet.bat HCP.MasterDataApi C:\Users\chris\Dropbox\Code\2017\VbaMeasureHcp\src MasterData\Api\HCP.MasterDataApi\bin\Debug\netcoreapp2.2\HCP.MasterDataApi.dll Solutions\.vs\MasterData\config\applicationhost.config
start iisaspnet.bat HCP.SecurityApi C:\Users\chris\Dropbox\Code\2017\VbaMeasureHcp\src Security\Api\HCP.SecurityApi\bin\Debug\netcoreapp2.2\HCP.SecurityApi.dll Solutions\.vs\Security\config\applicationhost.config
start iisaspnet.bat HCP.BillingApi C:\Users\chris\Dropbox\Code\2017\VbaMeasureHcp\src Billing\Api\HCP.BillingApi\bin\Debug\netcoreapp2.2\HCP.BillingApi.dll Solutions\.vs\Billing\config\applicationhost.config
start iisaspnet.bat HCP.ClientApi C:\Users\chris\Dropbox\Code\2017\VbaMeasureHcp\src Client\Api\HCP.ClientApi\bin\Debug\netcoreapp2.2\HCP.ClientApi.dll Solutions\.vs\Client\config\applicationhost.config
start iisaspnet.bat HCP.EmployeeApi C:\Users\chris\Dropbox\Code\2017\VbaMeasureHcp\src Employee\Api\HCP.EmployeeApi\bin\Debug\netcoreapp2.2\HCP.EmployeeApi.dll Solutions\.vs\Employee\config\applicationhost.config
The way the parameters work could likely be far simpler if the way the Projects, Solutions, etc were stored and named was more consistent, but, this is an existing set of Solutions I had no control over with scattered naming etc, and, the chaos above may be more helpful anyway for understanding how to call these commands.
The result is that running one command kicks off 6 IIS Express command windows for me, requests get logged to each of their windows, and I just type Q in each window to kill them.

Unauthorized nuget package from Visual Studio Team Services using asp.net core rc2

I am unable to install/restore nuget packages from a Visual Studio Team Services feed in an asp.net core web application (RC2). I receive the following:
error: Response status code does not indicate success: 401
(Unauthorized).
I am running Visual Studio Community 2015 Update 2 and nuget version 3.4.4. I am able to install/restore packages from this feed in other project types.
Do I need to do something else to pass my credentials for an asp.net core web app?
Steps to reproduce:
From Team Services package tab I select "Connect to Feed" and copy the NuGet package source URL
In visual studio -> Tools -> NuGet Package Manager -> Package Manager settings -> Package sources and add the feed url from vso
Then from my ASP.NET Core Web Application (.NET Framework) project right click references -> Manage NuGet Packages
-> Select my feed from Package source (packages are listed) -> Click to install
In output:
Installing NuGet package xxxxx
Successfully installed xxxxx to WebApplication1
========== Finished ==========
Then it will try to restore the package at which point I get:
error: Response status code does not indicate success: 401 (Unauthorized).
error: Failed to retrieve information from remote source
And inside web project references - package has warning icon - NU1001 The dependency xxxxx could not be resolved
I know that it's not exactly the same issue, but people may come across this one alongside as I did.
I have installed VS Community 2019​ and yesterday I decided to remove the VS 2017, but after that, when I tried to restore the Nuget Packages made by the company, it started displaying an error of 401 Unauthorized.
After a few net searches I decided I didn't want to mess around with VS configurations and files, I then realized, since it's an 401 Unauthorized it's related with an account so what I did was:
Closed VS2019
Went to windows management credentials and removed all those that where related with my packages
Reopened VS 2019 and restored the Nuget Packages for my solution.
It them asked for my credentials, set it up and all went well from here.
Here are the two accounts I removed and got recreated:
In my case I was using an azure dev ops feed. After updating visual studio 2022 I started getting this message "Response status code does not indicate success: 401 (Unauthorized)."
I followed and tried most of the solutions here. but what worked for me was to
Go to: file -> accounts settings
Click "sign out"
Then go to the nuget manager and click the refresh button
This will then show you the azure dev ops login window where you login to your account
This worked for me, (your mileage may vary) just hope it helps someone else and saves some precious receding hairs.
I can reproduce your issue at my side and following is the workaround I use to restore the packages:
Remove the VSTS feed resource from "VS\Tools\NuGet Package Manager\Package sources".
Open "Packages" tab from your VSTS web portal.
Select the feed you want to connect and click "Connect to feed" option.
Select "Personal Access Tokens" method in the dialog.
Copy the generated command in the dialog.
Run CMD as Administrator on you machine.
Paste the copied command into CMD.
Add "-StorePasswordInClearText" argument after the command.
Run the command.
Restart the VS.
Install and restore the packages.
For me, the issue was due to incorrect credentials (not specifying the domain) when connecting to a private on-premise Azure Artifacts NuGet feed, which wasn't immediately apparent.
Using Visual Studio 2019, open NuGet Package Manager for a project. If the 'Browse' tab shows first and the package source is the private NuGet feed, there appears to be no issue as it initially lists all packages. However, switching to the 'Installed' tab results in a login dialogue popping up.
If I enter my username and password without the domain (so username intead of domain/username), it appears to accept this, but then no other versions are listed for my installed packages other than the version installed. If I go to the 'Browse' tab, I then see the following error:
When I click 'Show errors in output', I see the following:
Failed to retrieve metadata from source 'https://[domain]/[Collection]/_packaging/[GUID]/nuget/v3/query2/?q=&skip=0&take=26&prerelease=true&semVerLevel=2.0.0'.
Response status code does not indicate success: 401 (Unauthorized).
To resolve this, in Credential Manager, I close Visual Studio, then remove any credentials relating to the Azure DevOps server(e.g., [domain], VSCredentials_[domain]). I noticed that the username for these showed the wrong domain - it showed the Azure DevOps server domain instead of the Active Directory domain.
I then reopen Visual Studio, open NuGet Package Manager again and this time (on the 'Installed' tab) enter my credentials including the domain (domain/username). This resolves the issue and allows me to connect to the Azure Artifact NuGet feed.
This happens when you change your profile password. Just sign out and from top right (at your profile picture-> account settings); sign in again and your problem will be solved.
I had a similar problem (no authentication) in the NuGet Restore task of a VSTS build definition. The solution was to add a NuGet.config file in the root of the project with a reference to the official and my custom feed. Maybe it helps your core project also.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
<add key="RmlrTools" value="https://<MyProjectName>.pkgs.visualstudio.com/DefaultCollection/_packaging/<MyFeedName>/nuget/v3/index.json" />
</packageSources>
<!-- used to store credentials -->
<packageSourceCredentials />
<!-- Used to specify which one of the sources are active -->
<activePackageSource>
<!-- this tells only one given source is active -->
<add key="NuGet official package source" value="https://nuget.org/api/v2/" />
<!-- this tells that all of them are active -->
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<!-- Used to disable package sources -->
<disabledPackageSources />
<!--
Used to specify default API key associated with sources.
See: NuGet.exe help setApiKey
See: NuGet.exe help push
See: NuGet.exe help mirror
-->
<!--<apikeys>
<add key="http://MyRepo/ES/api/v2/package" value="encrypted_api_key" />
</apikeys>-->
</configuration>
Try restarting the computer before you try any of the above.
In my case , I followed these steps
create the personal access token with relevant credentials
download nuget.exe (nuget cli)
using windows run command open the cmd,then
cd C:\Downloads(where the cli is downloaded) ,type
"nuget.exe" and enter
execute -->
nuget.exe sources Add -Name "MyFeedName" -Source "https://myfeedurl" -username username -password MyAccessToken
in visual studio tools->commandline->developer command prompt
dotnet restore
Go to "Manage Nuget Packages"
Click "Setting" from right top Corner
Untick "Packages"
In my case I was using Azure Devops private feed and the NuGet package restoring worked in Visual Studio and in Nuget CLI but it didn't work with Rider and dotnet restore command
The solution was to install The Azure Artifacts Credential Provider and it fixed the problem. I just had to run this command to install it:
iex "& { $(irm https://aka.ms/install-artifacts-credprovider.ps1) }"
This is a fix for a local developer machine. For fixing it on CI/CD check this question.
I'm using VS 2022. The way I was able to fix it is to relog into VS. The trick is the tooltip on the top right SAYS I'm logged in, but when you click your profile logo on the top right, then goto Account Settings, it told me I needed to "reenter my credentials". How does that work, I'm logged in, but I'm not logged in? Turns out it doesn't work, I needed to log in AGAIN for it to REALLY work.

Problem with installing windows service using CC.NET and MSBUILD

I am trying to install a windows service using MSBuild and CCNET. I am using MSBuild Extension pack WindowsService
task to install and start the windows service as part of automated build. The script section look like this
<!--install service-->
<MSBuild.ExtensionPack.Computer.WindowsService TaskAction="Install" ServiceName="$(PrServiceName)" ServicePath="$(PrServicePath)" User="$(User)" />
<!--set service to run automatically on restart-->
<MSBuild.ExtensionPack.Computer.WindowsService TaskAction="SetAutomatic" ServiceName="$(PrServiceName)" />
<!--start service-->
<MSBuild.ExtensionPack.Computer.WindowsService TaskAction="Start" ServiceName="$(PrServiceName)" ServicePath="$(PrServicePath)" User="$(User)" />
Now as soon as the the first task runs to install the service, it fails with the following error
E:\Data\cc_temp\Projects\cubic\intranet\pr\pr.build (137,3): error : Install Service failed with code: 'AccessDenied'
I assume this is because the script is running under cruise control service user account which does not have the appropriate permissions for installing a windows service.
I would just like to give minimal permissions to the cruise control user account instead of giving the full administrative rights.
Does anyone out there knows how can i achieve this?
Awaiting
Nabeel
Nabeel you are on the right track, it has to be a permissions issue. We do this all the time in our build using the same tools and it works. Have you checked to see which account the service is running as? and using the same user account to run your cruisecontrol? at least then you would possibly prove/disprove the permissions issue.