I am trying to change the Nu-Get package based on the debugging/release profile in visual studio 2022. This is very similar to This question however none of those solutions are working here. I created a standard console project to connect to Informix using the DB2 libs. Which runs fine. I added "docker support" through right clicking on the project in visual studio and it created a "profile" for Docker. I still have the standard Debug and Release configurations but now I have an additional drop down after the processor selection that has InformixConnect (appName), Docker, and WSL. It runs fine in Docker, which is linux, if I switch the reference manually to the linux version. I am trying to change the PackageReference value in .csproj when Docker is selected. I Tried every variation using Conditional in the linked question above, all failed to work. Any help would be appreciated.
launchsettings.json
{
"profiles": {
"InformixConnect": {
"commandName": "Project",
"commandLineArgs": "192.168.10.29"
},
"Docker": {
"commandName": "Docker"
},
"WSL": {
"commandName": "WSL2",
"environmentVariables": {},
"distributionName": ""
}
}
}
Top of .csproj.user
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>Docker</ActiveDebugProfile>
<_LastSelectedProfileId>C:\source\tests\InformixConnect\InformixConnect\Properties\PublishProfiles\registry.hub.docker.com_sgums.pubxml</_LastSelectedProfileId>
</PropertyGroup>
current .csproj - I have tried numerous variations on this without success.
<Project Sdk="Microsoft.NET.Sdk;Microsoft.NET.Sdk.Publish">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<Platforms>AnyCPU;x64</Platforms>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
<PackageReference Include="Net5.IBM.Data.DB2-lnx" Version="5.0.0.500" Condition="$([MSBuild]::IsOsPlatform('Linux'))" />
<PackageReference Include="Net5.IBM.Data.DB2" Version="5.0.0.500" Condition="$([MSBuild]::IsOsPlatform('Windows'))" />
</ItemGroup>
</Project>
msbuild diag output regardless of profile shows
OS = Windows_NT
The only thing I can see in the msbuild output that is changing is
ActiveDebugProfile = InformixConnect
vs
ActiveDebugProfile = Docker
Tried to run a conditional off every variation of Profile I could think of, but it didn't work.
links to my different msbuild outputs if interested. console app and docker.
Updated -
Feel free to download the repo and check it out. I appreciate everyone's help and would love to get this figured out.
Related
I don't know what else to test hence my question here.
The goal is to continue using my Visual Studio project set to<Project Sdk="Microsoft.NET.Sdk.Web"> and being able to obtain a Powershell session via the Powershell.SDK nuget package.
I noticed that running "powerShell.Invoke()" with a Visual studio project set to <Project Sdk="Microsoft.NET.Sdk"> will give me a session as expected. However using Sdk.Web always returns an error => "An error occured that Powershell could not handle".
I even added a project reference to a console application in order to get the session working but the result is the same as explained above.
Am I doing something wrong or is there any workaround?
Could I change my .net web application to a console app and still host it on IIS?
Thank you.
Was able to fix this by adding
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
and
<PackageReference Include="Microsoft.Management.Infrastructure" Version="1.0.0" />
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.0.4" />
<PackageReference Include="System.Management.Automation" Version="6.0.4" />
to csproj file as stated here: Issue
Also I had to set the RuntimeIdentifier to win7-x64 in my publish profile:
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
I have created an Azure function that is called via webhook from Dynamics 365. A simple scenario to read the remote context object does work; however, a more complex scenario throws an error. Tried to get an instance of the Dynamics service object using CrmServiceClient (Microsoft.Xrm.Tooling.Connector) but it throws an error when this line runs CrmServiceClient client = new CrmServiceClient(crmConnectionString):
"Could not load type 'Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior' from assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.14.2.11, Culture=neutral, PublicKeyToken=31bf3856ad364e35'"
I have checked the DLLs in the bin directory in Azure and the version for Microsoft.IdentityModel.Clients.ActiveDirectory is 2.22.
Also, I checked the xxx.deps.json file in Azure and it shows the same version:
"Microsoft.IdentityModel.Clients.ActiveDirectory/2.22.0.0": {
"runtime": {
"Microsoft.IdentityModel.Clients.ActiveDirectory.dll": {
"assemblyVersion": "2.22.0.0",
"fileVersion": "2.22.30211.1727"
}
}
I have searched for version 3.14.2.11 for the mentioned DLL but cannot find it. So I wonder why is Azure loading that version?
Following the advice of some other postings, I have added a file -function.proj- under my function's folder with the idea to downgrade the version of that DLL that Azure loads, here's the content:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="2.22.0" />
</ItemGroup>
</Project>
Unfortunately, it hasn't changed the outcome. Has anyone run into the same issue?
The package Microsoft.Xrm.Tooling.Connector is depend on .net framework 4.6.2, while your azure function TargetFramework is netstandard 2.0. So make sure your function's runtime version.
Then upgrade Microsoft.IndentityModel.Client.ActiveDirectory to 2.28.3 version.
If your function runtime is ~1, create project.json with following content.
{
"frameworks": {
"net46":{
"dependencies": {
"Microsoft.IdentityModel.Clients.ActiveDirectory": "2.28.3"
}
}
}
If your function runtime is ~2, create function.proj as below.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.IndentityModel.Client.ActiveDirectory" Version="2.28.3"/>
</ItemGroup>
</Project>
Just downgrading the runtime to version 1 did the trick.
I'm not sure how to set the default nuget feed for my .net core project in Visual Studio Code to https://api.nuget.org/v3/index.json
When I attempt to add a package (and subsequently, restore dependencies), I get the following errors...
C:\Program Files\dotnet\sdk\2.1.403\NuGet.targets(114,5): error : Unable to load the service index for source https://smartassessor.pkgs.visualstudio.com/_packaging/SANuget/nuget/v3/index.json. [c:\Users\Matthew.OConnor\Desktop\Important Documents\Programming\DatingApp\DatingApp.API\DatingApp.API.csproj]
C:\Program Files\dotnet\sdk\2.1.403\NuGet.targets(114,5): error : Response status code does not indicate success: 401 (Unauthorized). [c:\Users\Matthew.OConnor\Desktop\Important Documents\Programming\DatingApp\DatingApp.API\DatingApp.API.csproj]
This source https://smartassessor.pkgs.visualstudio.com/_packaging/SANuget/nuget/v3/index.json has nothing to do with my current project, however it is used for other projects that are typically run using full blown Visual Studio. Those projects are saved in a completely different place to this project.
I simply want to be able to add nuget packages from nuget.org in my .net core project. How do I do this in VS code?
I don't currently have a nuget.config file in this project.
The package source mentioned in the error appears to be coming from a package source I have setup whilst using Visual Studio
This is my csproj file...
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4"/>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="4.0.1"/>
<PackageReference Include="CloudinaryDotNet" Version="1.3.1"/>
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.1.0-preview1-final"/>
</ItemGroup>
</Project>
CloudinaryDotNet is the package that generated the errors above.
I think VS Code is just running a dotnet restore, and the reason you're seeing this source being used is because it's configured in your User/Computer nuget configuration file (located on windows, which you seem to be running, at %appdata%\NuGet\NuGet.Config & %ProgramFiles(x86)%\NuGet\Config respectively). The VS configuration editor you showed is just a nice GUI for this configuration file.
If you want to keep this general setting, you should be able to use a nuget.config file in your VS Code project (which you mentioned you don't have at the moment). There is more info on this here -Add custom package source to Visual Studio Code.
Also, if you're trying to restore manually, you can use one of these 2 flags -
dotnet restore --source https://api.nuget.org/v3/index.json
dotnet restore --ignore-failed-sources
These are pretty self explanatory, but you can see the full documentation here - https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-restore?tabs=netcore2x
Hope this helps (:
My webb app works fine when run from Visual Studio, but when I publish and try to load a page, I get:
InvalidOperationException: Cannot find compilation library location for package 'Microsoft.AspNet.WebApi.Client'
Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths(ICompilationAssemblyResolver resolver, List assemblies)
I've been stuck on this for quite a while. I've attempted to apply the various workarounds in the thread https://github.com/dotnet/core-setup/issues/2981, but none of them have worked.
My csproj file is pasted below. I'm not sure what other information would be useful:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<UserSecretsId>aspnet-CrowdQuery2-8C668DB3-5C80-4D9E-851D-2434D0CDA7E9</UserSecretsId>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>
<PropertyGroup>
<RuntimeFrameworkVersion>2.1.2</RuntimeFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.6" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.3" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<Folder Include="ViewModels\" />
</ItemGroup>
</Project>
I've been having the same issue using Microsoft Azure.
The solution in this case was to clean up the wwwroot folder in our web app using Kudu (Development Tools -> Advanced Options), because there were some old DLLs still left from before the upgrade to .NET Core 2.1, because .NET Core 1 publishes the DLLs to the wwwroot folder, whereas in 2.1, the DLLs are loaded from a global store.
After having completely emptied the wwwroot folder, and redeploying the app, the error was resolved and the app ran as expected.
I had to
(1)
Edit .csproj and add
<PropertyGroup>
<MvcRazorExcludeRefAssembliesFromPublish>False</MvcRazorExcludeRefAssembliesFromPublish>
</PropertyGroup>
(2)
Change the publish "Target Runtime" to "win-x64" (it was previously x86). I don't know why this is required, because my project properties -> Platform target is "Any CPU".
(I have two other similar websites in the same solution, neither of those .csproj files require that line, and both are still publishing to x86).
The command "dotnet bundle" exited with code 1
I am getting above error while publishing the .net core 1.1 app in VS 2017.
I suspect the issue to be related to tool sections which are missing in cs.proj file in VS 2017.
"tools": {
"BundlerMinifier.Core": "2.2.281"
In VS 2015 it used to be done as above as in the below link.
No executable found matching command "dotnet-bundle" during WebDeploy for ASP.NET Core
How to add tool section in csproj file in VS 2017 for .net core 1.1 app?
The project.json to csproj mapping docs are your friend! Here's how the tools section maps over:
{
"tools": {
"BundlerMinifier.Core": "2.2.281"
}
}
becomes
<ItemGroup>
<DotNetCliToolReference Include="BundlerMinifier.Core" Version="2.2.281" />
</ItemGroup>
It should be fairly obvious when you look at your .csproj file how it's structured. But just incase.
<Project>
...Other stuff here
<ItemGroup>
<DotNetCliToolReference Include="Your.Package.Name.Here" Version="x.x.x" />
</ItemGroup>
...Other stuff here
</Project>