VS 2017中新的Xamarin项目的多个“找不到资源...”和“错误接收项目的父项”

时间:2018-09-11 14:14:59

标签: visual-studio xamarin xamarin.forms visual-studio-2017

我在Visual Studio 2017社区版15.8.3中为Xamarin创建了一个新项目。然后我在MainPage.xamlcs中添加了一些更改,现在在构建解决方案时遇到了这些错误。

enter image description here

错误指的是我没有碰到的styles.xml

我之前看到此错误,要求重新启动VS,重新启动计算机,清理objbin目录,升级VS等。

我不想盲目地做这些事情。

这个问题有系统的解决方案吗?

2 个答案:

答案 0 :(得分:0)

这在针对Android 7.1的VS2017跨平台解决方案中为我工作:

  1. 清理您的项目并重建它。
  2. 更改每个XAML文件属性: 将“生成操作”从“嵌入式资源”更改为“编译”或“ C#编译器”
  3. 重建项目(这会产生错误)
  4. 关闭VS2017并删除.VS文件夹并重新打开解决方案
  5. 更改每个XAML文件属性: 将“构建操作”更改回“嵌入资源”
  6. 重建,对我有好处。

在一个单独的项目中,上述解决方案无法解决我的错误,并且我还成功地执行了以下其他步骤:

  1. Using this guide,我能够确定自己缺少以下Nuget参考:
import pygame as pg
from pygame.math import Vector2


pg.init()
LIGHTBLUE = pg.Color('lightskyblue2')
DARKBLUE = pg.Color(11, 8, 69)

screen = pg.display.set_mode((800, 600))
width, height = screen.get_size()
clock = pg.time.Clock()
# You need surfaces with an alpha channel for the masks.
bluecar = pg.Surface((60, 30), pg.SRCALPHA)
bluecar.fill((0,0,255))
BALL = pg.Surface((30, 30), pg.SRCALPHA)
pg.draw.circle(BALL, [0,0,0], [15, 15], 15)
ball_pos = Vector2(395, 15)
ballrect = BALL.get_rect(center=ball_pos)
ball_vel = Vector2(0, 0)
mask_blue = pg.mask.from_surface(bluecar)
mask_ball = pg.mask.from_surface(BALL)
pos_blue = Vector2(740, 500)  # Just use the pos vector instead of x, y.
bluerect = bluecar.get_rect(center = pos_blue)
vel_blue = Vector2(0, 0)  # Replace x_change, y_change with vel_blue.
# A constant value that you add to the y-velocity each frame.
GRAVITY = .5
on_ground = False
ground_y = height - 100

done = False
while not done:
    for event in pg.event.get():
        if event.type == pg.QUIT:
            done = True
        elif event.type == pg.KEYDOWN:
            if event.key == pg.K_a:
                vel_blue.x = -5
            elif event.key == pg.K_d:
                vel_blue.x = 5
            elif event.key == pg.K_w:
                if on_ground:  # Only jump if the player is on_ground.
                    vel_blue.y = -12
                    on_ground = False
        elif event.type == pg.KEYUP:
            if event.key == pg.K_a and vel_blue.x < 0:
                vel_blue.x = 0
            elif event.key == pg.K_d and vel_blue.x > 0:
                vel_blue.x = 0

    ball_vel.y += GRAVITY  # Accelerate downwards.

    ball_pos += ball_vel  # Move the ball.
    ballrect.center = ball_pos  # Update the rect.
    # Bounce when the ball touches the bottom of the screen.
    if ballrect.bottom >= ground_y:
        # Just invert the y-velocity to bounce.
        ball_vel.y *= -0.7  # Change this value to adjust the elasticity.
        ball_vel.x *= .95  # Friction
        # Don't go below the ground.
        ballrect.bottom = ground_y
        ball_pos.y = ballrect.centery
    # Left and right wall collisions.
    if ballrect.left < 0:
        ball_vel.x *= -1
        ballrect.left = 0
        ball_pos.x = ballrect.centerx
    elif ballrect.right > width:
        ball_vel.x *= -1
        ballrect.right = width
        ball_pos.x = ballrect.centerx

    # Add the GRAVITY value to vel_blue.y, so that
    # the object moves faster each frame.
    vel_blue.y += GRAVITY
    pos_blue += vel_blue
    bluerect.center = pos_blue  # You have to update the rect as well.

    # Stop the object when it's near the bottom of the screen.
    if bluerect.bottom >= ground_y:
        bluerect.bottom = ground_y
        pos_blue.y = bluerect.centery
        vel_blue.y = 0
        on_ground = True
    if bluerect.x < 0:
        bluerect.x = 0
        pos_blue.x = bluerect.centerx
    elif bluerect.right > width:
        bluerect.right = width
        pos_blue.x = bluerect.centerx

    offset_blue = bluerect[0] - ballrect[0], bluerect[1] - ballrect[1]
    overlap_blue = mask_ball.overlap(mask_blue, offset_blue)
    if overlap_blue:  # Blue collides with the ball.
        if vel_blue.x != 0:  # Player is moving.
            ball_vel = Vector2(vel_blue.x, -17)
        else:  # If the player is standing, I just update the vel.y.
            ball_vel.y = -17

    # Draw everything.
    screen.fill(LIGHTBLUE)
    pg.draw.line(screen, (0, 0, 0), (0, ground_y), (width, ground_y))
    screen.blit(bluecar, bluerect)  # Blit it at the rect.
    screen.blit(BALL, ballrect)

    pg.display.update()
    clock.tick(60)

pg.quit()
  1. 清理并构建后,关闭,删除.VS文件夹,然后重新打开...我再次检查了日志,能够确定我缺少以下Nuget参考:
Xamarin.Android.Support.v7.AppCompat
  1. 又一次清理和构建,这些问题消失了……剩下了我能够解决的残余代码问题。

  2. 经过另一次清理和构建后,我收到另一个错误,我缺少以下Nuget参考:

Xamarin.Android.Support.Design
  1. 另一个清理和构建...没有错误。

答案 1 :(得分:0)

enter image description here

MainPage.xaml

中查看是否未更改任何设置

如果不在此处放置您的内容,只是为了查看是否有人看到错误。