dotnet publish single file using VisualStudio - c#

I'm trying to publish a single file for a c# wpf application ( net core 6 ), without success: the pdb files are always added to the output folder. It needs to be done using VS for ... reasons.
1- Created the publish profile
2.1- Added the following line to the cs proj i'm trying to build
<IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
2.2- Added the following lines to all the projects in the solution
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
3- The solution also has a global NuGet.config file, and my feeling is that the issue is here: if i use the "RestorePackages" condition, no error is found but the pdbs are generated. If I don't use the condition, i get a build error. If I remove the "PackageRestore", everything is ok but it affects the debug mode, which is mandatory to have automatic restore.
<RestorePackages Condition="$(RestorePackages) == '' AND '$(Configuration)' == 'Release'">false</RestorePackages>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<packageSources>
<clear />
<add key="mySource" />
</packageSources>
??
What am i missing? Thanks

Related

Can't read app.config appSettings from unit test in JetBrains Rider

I am using ConfigurationManager.AppSettings["someKey"] to retrieve values from app.config appSettings
<appSettings>
<add key="someKey" value="value" />
...
However, when I use this in my unit tests, the ConfigurationManager.AppSettings collection is empty.
This happens only when I run the tests from JetBrains Rider IDE!
Running them from Visual Studio (even with ReSharper runner) works perfectly fine and values are loaded.
It is a .Net 5 project using XUnit framework.
What is going on with Rider here?
First make sure the app.config is in the correct format. since you want to reference ConfigurationManager.AppSettings["someKey"]
the app.config should be structed this way
<configuration>
<appSettings>
<add key="someKey" value="value" />
</appSettings>
</configuration>
copy the app.config to the project-folder\bin\Debug\net5.0 and rename in a way that is understood by the IDE which can be achieved through adding the following lines in project file
<Target Name="CopyCustomContent" AfterTargets="AfterBuild" >
<Copy SourceFiles="app.config" DestinationFiles="$(OutDir)/ReSharperTestRunner.dll.config" />
<Target/>
Hope this helps!!

VSTS unable to load the service index for source 401

I'm aware of the other posts about the same signature. I still can't resolve my issue after going thru them.
My team uses VSTS's build definition for continuous integration.
This build definition works fine until the lastes pull request.
I'm running into the error msg below during the Nuget Restore
2018-06-20T00:37:27.6438127Z System.AggregateException: One or more errors occurred. ---> NuGet.Protocol.Core.Types.FatalProtocolException: Unable to load the service index for source https://microsoft.pkgs.visualstudio.com/_packaging/CBT/nuget/v3/index.json. ---> System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
I do have https://microsoft.pkgs.visualstudio.com/_packaging/CBT/nuget/v3/index.json in the nuget.config, and there is nothing changed in the nuget.config in the failing PR
I can nuget restore and build the entire solution successfully on my local machine using VS2017. The only related change in the PR is that instead of using package.config, it uses packagereference to get the nuget package. I tried to move back to using package.config, the build would still fail with the same error msg.
Thanks in advance.
You can update the VSTS feed with credentail (PAT or alternate credential) in the specified nuget.config file.
Such as:
nuget sources update -Name "vstsfeed" -Source https://microsoft.pkgs.visualstudio.com/_packaging/CBT/nuget/v3/index.json -Username "Alternate username" -Password "alternate password" -configfile /path/to/nuget.config
Then you can commit the changes for the nuget.config file and push to VSTS repo. And build again to check if it works.
You can use a command as shown in the accepted answer - also, you can add the feed in a nuget.config file placed in the root of your repo
Notice, this shows how to add credentials for a custom feed with spaces in the feed name: My Nuget Artifacts
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<!-- Allow NuGet to download missing packages -->
<add key="enabled" value="True" />
<!-- Automatically check for missing packages during build in Visual Studio -->
<add key="automatic" value="True" />
</packageRestore>
<packageSources>
<add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" />
<add key="My Nuget Artifacts" value="https://pkgs.dev.azure.com/ConsotoOrg/_packaging/Consoto/nuget/v3/index.json" />
</packageSources>
<packageSourceCredentials>
<My_x0020_NuGet_x0020_Artifacts>
<add key="Username" value="justme" />
<add key="ClearTextPassword" value="xyzyoqyvslyfs1t1khru6wd33gebujhpr9moocbujfhv8ukxtxyz" />
</My_x0020_NuGet_x0020_Artifacts>
</packageSourceCredentials>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
<!--
Used to specify trusted signers to allow during signature verification.
See: nuget.exe help trusted-signers
-->
<trustedSigners>
<author name="microsoft">
<certificate fingerprint="3F9001EA83C560D712C24CF213C3D312CB3BFF51EE89435D3430BD06B5D0EECE" hashAlgorithm="SHA256" allowUntrustedRoot="false" />
</author>
<repository name="nuget.org" serviceIndex="https://api.nuget.org/v3/index.json">
<certificate fingerprint="0E5F38F57DC1BCC806D8494F4F90FBCEDD988B46760709CBEEC6F4219AA6157D" hashAlgorithm="SHA256" allowUntrustedRoot="false" />
<owners>microsoft;aspnet;nuget</owners>
</repository>
</trustedSigners>
</configuration>
FWIW - In recent days, I've found I can clear up some NuGet restore errors by removing the trustedSigners section from the config
This is not what the problem was with the OP but I'm adding a note here since I found this question while searching for the same error message.
In our case we were building a .net 5 app for in Azure DevOps. We had to upgrade to a newer version of NuGet using the NuGet tool installer. Then the restore worked just fine using the .Net Core task with the restore command.

VS2015 NuGet private package repo source not updating

I have an issue in VS2015 where adding a NuGet source is not working.
The picture below shows the source. The URL and package name is correct and working (I can successfully push packages to the repo).
The problem is when I add it, check the checkbox, and select "Update" and "Save", it does not activate the source. When I go back into the dialog, the checkbox is unchecked. It remains unchecked no matter what I do.
I think this is a GUI issue, the problem seems to be it simply is not enabling it. Is there a config option in a project file I can manually this package source?
(Note that "NAME" and "http://myrepo.com" are not the real source name and url, but I have verified they are correct by pushing to it successfully.
Edit:
I checked the NuGet.config file and there is indeed an entry in the file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageRestore>
<add key="enabled" value="True" />
<add key="automatic" value="True" />
</packageRestore>
<packageSources>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="NAME" value="http://myrepo.com" />
</packageSources>
<disabledPackageSources />
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
I had been running VS as administrator due to using a local IIS instance which requires administrator privileges, magicandre1981 pointed out that NuGet.config needs write permissions, so I gave full access to the folder to normal users (I believe the NuGet.config file was generated under the administrator context therefore lacking normal user permissions).
This by itself did not solve the issue, but doing a Nuget Package Restoreafterwards, caused the NuGet feed to display again.

How can i write a custom html helpers with suggestions for parameter [duplicate]

I can't get intellisense for my own html helpers. My CustomHtmlHelpers.cs looks like this:
using System.Web.Mvc;
using System.Text;
using System.Web;
namespace laget.Web.Helpers
{
public static class CustomHtmlHelpers
{
//MY HELPERS
}
}
and in my Web.config:
<pages>
<namespaces>
<add namespace="laget.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages"/>
<add namespace="System.Web.Helpers" />
</namespaces>
</pages>
If I put <#using laget.Web.Helpers> in my view, I get the intellisense issue fixed.
Should it not be enough with the code in Web.config?
Sometimes it doesn't seem to work right away. Try closing the .cshtml file, and re-opening it. Then if that doesn't work, try restarting Visual Studio. Also make sure you actually compiled your project, intellisense won't work with non-compiled helpers.
I'm pretty sure that you're not editing the correct Web.config file.
You need to add your namespace to the one in your Views directory.
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="laget.Web.Helpers" />
</namespaces>
</pages>
</system.web.webPages.razor>
You actually don't need to restart Visual Studio in most cases. All you need to do is close the .cshtml file and reopen it!
It needs it on the local page. I'm pretty sure this has to do with Namespace resolution. It isn't exactly sure what you are referring to without the local using statement.
I ran into this today as well. Sometimes just closing the Razor view's window in Visual Studio and re-opening it will do the trick without having to do a full Visual Studio restart.
I tried to solve an issue like this one yesterday. I had e pre-compiled dll (project name ie: MyHtmlHelpers) containing helpers and lot of other classes.
I had the assembly referenced in the web project and the all "standard"-helpers showed up in intellisense but, even though I added the namespace to both web.config in the root and in the views-folder nothing worked. When running the project helpers works, but not in intellisense.
I added a new class and wrote a new html helper inside the web project, added the namespace to web.config. And that worked.
After some hours add tried my last card, adding the MyHtmlHelpers-project to the same solution as my webproject. That did the trick. I diden't change anything in the configs just added the project to the same solution and changed the reference to point at the project insted of the compiled dll.
Isen't that strange? A VS-bug?
I found that i was adding the reference to the wrong web.config. It's not the main config but the web.config in the views directory...
So now I will show you the steps
1.Create or open an existing class library project (if you open an existing one be sure to remove the MVC5 nuget package)
2.Add the MVC (5.0) nuget package (
right click project in solution explorer -> Manage NuGet Packages -> search for MVC and install “Microsoft ASP.NET MVC”)
3.Close any and all open .cshtml files
4.Right click project -> Properties -> Build -> change Output path to your project “bin/”
5.Add the following minimal Web.config to the root of your class library project
( the web config file is solely needed for intellisense. Configuration (via Web.config)
should be done in the WebApplication hosting your ClassLibrary assembly)
6.Clean and Build the solution.
7.Open cshtml file and try now :)
I found that if it still doesn't work, you may need to go to the properties of the custom class and change the build action from "content" to "compile". That resolved it for me.
I try all of this solutions, one more thing which i didnt find is that in root web.config i must change webpages:Version from 2.0.0.0 to 3.0.0.0.
Open and close all .cshtml files and it's worked.
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />

C# - Use configuration file in Debug mode

I discovered few days ago that we can use Configuration files in .NET and trying to use it in my applications.
First of all, configure correctly the use of configuration file is really borring :
Configuration file should have the same name as the application (understandable)
Then think to add the System.Configuration reference (understandable too)
When file is added, go in it's properties and change it to copy the file in output directory (less understandable).
Configuration file isn't taken into account in debug mode (because of *.vhosts.exe)
It takes me time to understand why this file wasn't taken into account...
So question is pretty simple, how can I fix this and use configuration files in Debug Mode ?
I would use it in order to configure my trace switches.
Here is my App.config file :
<configuration>
<appSettings>
<add key="A" value="B"/>
</appSettings>
<system.diagnostics>
<switches>
<add name="myFirstSwitch" value="1" />
<add name="MySecondSwitch" value="Error" />
</switches>
</system.diagnostics>
</configuration>
Thanks.
I think you created your config file the wrong way, the right way is:
On the Project menu, click Add New Item. The Add New Item dialog box
appears.
Select the Application Configuration
File template and then click Add. A
file named App.config is added
to your project.
This config file is automatically copied to the build folder when you build the project and works in both Debug and Release mode.

Categories