就在几天前,更新到 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
.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
我正在尝试将使用旧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) 我们目前正在将项目升级到新的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 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) 我在Visual Studio 2017中使用新的CSPROJ格式创建了一个WPF应用程序.
通过
我可以成功构建并运行该应用程序.但是,我有一个问题,即代码编辑器无法识别XAML中的任何控件,因此我在编辑器中得到错误的错误而没有智能感知.
项目文件:
<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)
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
我们需要在 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)