相关疑难解决方法(0)

资产文件project.assets.json没有“net6.0”的目标 - VS2022

就在几天前,更新到 Visual Studio Community 2022 v17.2(从 v17.1.6)后出现此错误:

错误 NETSDK1005 资产文件“C:.........XXXXXX.Web\obj\project.assets.json”没有“net6.0”的目标。确保恢复已运行并且您已将“net6.0”包含在项目的 TargetFrameworks 中。XXXXXX.Web C:\Program Files\dotnet\sdk\6.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets 267

  • 卸载与 VS2022 + 安装程序相关的所有内容
  • 重新启动
  • Fresh Git 克隆了我正在处理的项目(我在几台计算机上工作,所有计算机都装有 Win 10 并且都具有最新更新,这是唯一出现此问题的 VS 安装)
  • 重新安装 VS 2022 v17.2(使用 .NET 6.0,常规安装)

.csproj 文件已准备就绪:

<PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <RuntimeIdentifiers>win-x86;win-x64</RuntimeIdentifiers>
    <IsPackable>false</IsPackable>
    <SpaRoot>ClientApp\</SpaRoot>
    <DefaultItemExcludes>$(DefaultItemExcludes);(SpaRoot)\**\node_modules\**;</DefaultItemExcludes>
    <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

在构建或重建之前始终删除“bin”和“obj”文件夹......

无法摆脱编译,并且总是收到 NETSDK1005 错误...

PS - 已检查问题70711153

.net-6.0 visual-studio-2022

89
推荐指数
8
解决办法
9万
查看次数

WPF App使用新的csproj格式

我正在尝试将使用旧csproj格式定义的WPF项目迁移到VS 2017下的新格式.

使用我在如何将Wpf项目迁移到新的VS2017格式时发现的信息,我能够获得成功构建的大部分内容.

但是我坚持要克服这个错误:

错误CS5001:程序不包含适用于入口点的静态"主"方法

我的新式csproj文件如下:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <LanguageTargets>$(MSBuildExtensionsPath)\$(VisualStudioVersion)\Bin\Microsoft.CSharp.targets</LanguageTargets>
    <OutputType>winexe</OutputType>
    <TargetFramework>net47</TargetFramework>
    <ApplicationIcon />
    <OutputTypeEx>winexe</OutputTypeEx>
    <StartupObject />
  </PropertyGroup>

  <ItemGroup>
    <EmbeddedResource Update="Properties\Resources.resx" Generator="ResXFileCodeGenerator" LastGenOutput="Resources.Designer.cs" />
    <Compile Update="Properties\Resources.Designer.cs" DesignTime="True" AutoGen="True" DependentUpon="Resources.resx" />
    <Compile Update="Settings.Designer.cs" AutoGen="True" DependentUpon="Settings.settings" />
    <None Update="Settings.settings" LastGenOutput="Settings.Designer.cs" Generator="SettingsSingleFileGenerator" />

    <Page Include="**\*.xaml" SubType="Designer" Generator="MSBuild:Compile" />
    <Compile Update="**\*.xaml.cs" SubType="Designer" DependentUpon="%(Filename)" />

    <Resource Include="assets\*.*" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Autofac" Version="4.6.0" />
    <PackageReference Include="Autofac.Extras.CommonServiceLocator" Version="4.0.0" />
    <PackageReference Include="Extended.Wpf.Toolkit" Version="3.0.0" />
    <PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.0.8" />
    <PackageReference Include="MaterialDesignColors" Version="1.1.3" />
    <PackageReference …
Run Code Online (Sandbox Code Playgroud)

c# wpf visual-studio visual-studio-2017

16
推荐指数
1
解决办法
4324
查看次数

如何将旧的WinForms项目迁移到新的VS2017项目格式

我们目前正在将项目升级到新的VS2017项目格式.这背后的主要原因是将一些库从PCL转换为.NetStandard,并且能够使用新项目格式附带的新内置Nuget Package功能,从而摆脱整个nuget /库引用/依赖问题.

[编辑]迁移解决方案中所有项目的主要原因是为了防止在混合旧(仍在使用.nuspec)和新格式项目时在.nupkg中无法获得正确依赖关系的问题

如何将Wpf项目迁移到新的VS2017格式的问题的答案帮助我们在转换项目的WPF部分方面做了很多工作.但是,我们仍然有大量的Windows窗体,无法替换或升级.

只需转换项目文件,为文件依赖项添加适当的设置(对于*.Designer.cs和*.resx文件),我们设法让它进行编译.

我们现在如何以一种方式声明项目项目以使Visual Studio 2017 a)将它们识别为UserControl或Form?b)打开WinForms设计器工具来相应地编辑.cs或Designer.cs文件?

非常感谢任何寻找解决方案的暗示.

.net c# winforms visual-studio-2017 msbuild-15

10
推荐指数
1
解决办法
2019
查看次数

绑定重定向地狱

我有一个.Net Framework 4.6.1 WPF引用几个.Net Standard 2.0程序集的项目.这些程序集中的每一个都有自己的一个或两个依赖项,从NuGet引入.在Visual Studio内部,一切正常并且运行正常.但是,当我第一次尝试发布应用程序并运行它(在同一台机器上)时,我得到了这个令人讨厌的异常:

无法加载文件或程序集'System.Runtime,Version = 4.1.2.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一.该系统找不到指定的文件.

经过几天拉出我的头发,我终于发现将以下绑定重定向添加到我的项目的App.config解决了这个问题

<dependentAssembly>
  <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)

至少,它把问题转移到了System.ObjectModel.然后我添加了一个绑定重定向后,我得到了一个错误System.Collections,等等...不久之后,我的App.config看起来像这样:

<dependentAssembly>
  <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
</dependentAssembly>
<dependentAssembly>
  <assemblyIdentity name="System.ObjectModel" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
</dependentAssembly>
<dependentAssembly>
  <assemblyIdentity name="System.Collections" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
</dependentAssembly>
<dependentAssembly>
  <assemblyIdentity name="System.Reflection.Extensions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-4.0.11.0" newVersion="4.0.11.0" />
</dependentAssembly>
<dependentAssembly> …
Run Code Online (Sandbox Code Playgroud)

c# wpf assembly-binding-redirect .net-standard

9
推荐指数
1
解决办法
2393
查看次数

使用新的CSPROJ格式时,WPF控件在代码隐藏中无法识别

我在Visual Studio 2017中使用新的CSPROJ格式创建了一个WPF应用程序.

通过

我可以成功构建并运行该应用程序.但是,我有一个问题,即代码编辑器无法识别XAML中的任何控件,因此我在编辑器中得到错误的错误而没有智能感知.

代码编辑器中的错误错误

重现步骤

  1. 发布VS 2017
  2. 创建一个新的"WPF应用程序(.NET Framework)"C#项目
  3. 编辑csproj文件,如下所示:

项目文件:

<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
  <PropertyGroup>
    <LanguageTargets>$(MSBuildExtensionsPath)\$(VisualStudioVersion)\Bin\Microsoft.CSharp.targets</LanguageTargets>
    <TargetFramework>net45</TargetFramework>
    <ProjectGuid>{030D04DA-D603-4D4C-95F7-B6F725A6829E}</ProjectGuid>
  </PropertyGroup>
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
  </PropertyGroup>
  <PropertyGroup>
    <StartupObject />
  </PropertyGroup>
  <ItemGroup>
    <ApplicationDefinition Include="App.xaml">
      <Generator>MSBuild:Compile</Generator>
      <SubType>Designer</SubType>
    </ApplicationDefinition>
    <Page Include="MainWindow.xaml">
      <SubType>Designer</SubType>
      <Generator>MSBuild:Compile</Generator>
    </Page>
    <Compile Update="**\*.xaml.cs" SubType="Designer" DependentUpon="%(Filename)" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="PresentationCore" />
    <Reference Include="PresentationFramework" />
    <Reference Include="System.Xaml" />
    <Reference Include="WindowsBase" />
  </ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
  1. 在MainWindow.xaml中添加一个名为"button1"的按钮,如下所示:

MainWindow.xaml

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525"> …
Run Code Online (Sandbox Code Playgroud)

c# wpf visual-studio-2017 roslyn-project-system common-project-system

8
推荐指数
1
解决办法
1436
查看次数

在 WPF 自托管 asp.net 核心应用程序中加载视图

我们需要在 WPF 应用程序中自托管一个 Asp.Net Core 应用程序,API 工作正常,但加载 cshtml 视图存在一些问题。

这是我们的代码:Host Builder:

public static class HostBuilder
    {
        private static IWebHost host;

        public static async Task Start()
        {
            if (host == null)
            {
                var ip = System.Net.IPAddress.Parse("127.0.0.1");
                var port = 9388;

                host = new WebHostBuilder()
                   .UseKestrel(options =>
                   {
                       options.Listen(ip, port);
                   })
                   .UseStartup<HostStartup>()
                   .Build();

                await host.RunAsync();
            }
        }

    }
Run Code Online (Sandbox Code Playgroud)

主机启动:

public class HostStartup
    {
        public IConfiguration Configuration { get; }

        public HostStartup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public void ConfigureServices(IServiceCollection services)
        { …
Run Code Online (Sandbox Code Playgroud)

c# wpf asp.net-core-mvc asp.net-core

4
推荐指数
1
解决办法
1859
查看次数